:root {
  --accent: #14b8a6;
  --accent-strong: #0f766e;
  --accent-soft: #ccfbf1;
  --blue: #2563eb;
  --green: #059669;
  --orange: #d97706;
  --red: #dc2626;
  --page-bg: #f4fbfa;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-soft: #f8fbfd;
  --line: #d9e8e6;
  --line-strong: #b9d7d2;
  --text: #172033;
  --text-soft: #526174;
  --text-dim: #78869a;
  --shadow: 0 18px 45px rgba(21, 94, 117, 0.11);
  --section-gap: 22px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background:
    linear-gradient(180deg, rgba(236, 253, 245, 0.96), rgba(239, 246, 255, 0.96)),
    linear-gradient(90deg, rgba(20, 184, 166, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(20, 184, 166, 0.08) 1px, transparent 1px);
  background-size: auto, 44px 44px, 44px 44px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  padding: 24px;
  position: relative;
}

body.centered {
  align-items: center;
  display: flex;
  justify-content: center;
}

body::before,
body::after,
.scanline {
  display: none;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

.container,
.shell {
  margin: 0 auto;
  max-width: 1000px;
  position: relative;
  width: 100%;
  z-index: 1;
}

.shell {
  padding: 10px 0 44px;
}

.container.wide,
.shell.wide {
  max-width: 1400px;
}

.header {
  animation: fadeInDown 0.45s ease;
  margin-bottom: 28px;
  text-align: center;
}

.header h1 {
  color: #0f766e;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 10px;
}

.header p,
.section-title p,
.data-header p,
.status,
.hint {
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.6;
}

.card,
.panel,
.stat-card,
.message,
.mini-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card {
  animation: fadeIn 0.35s ease;
  padding: 36px 42px;
}

.panel {
  animation: fadeIn 0.35s ease;
  padding: 28px;
}

.workspace {
  display: grid;
  gap: var(--section-gap);
  margin-top: var(--section-gap);
}

.workspace.hidden,
.hidden {
  display: none;
}

.section-title,
.data-header {
  margin-bottom: 20px;
}

.tabs {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px;
}

.tab-button {
  border-color: transparent;
  color: var(--text-soft);
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
}

.tab-button:hover {
  background: #f0fdfa;
  border-color: transparent;
  color: var(--accent-strong);
}

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

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-title h2,
.panel h2,
.data-title {
  color: #0f766e;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.data-header {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
}

.header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.inline-form,
.actions,
.buttons {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  min-height: 46px;
  padding: 0 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

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

input:focus,
select:focus,
textarea:focus {
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.15);
  outline: none;
}

input[readonly] {
  background: #f1f8f7;
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #9aa8b6;
}

.inline-form input,
.inline-form select,
.inline-form .custom-select {
  flex: 1 1 260px;
}

.native-select-hidden {
  border: 0 !important;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  display: none !important;
  height: 1px !important;
  min-height: 0 !important;
  overflow: hidden;
  padding: 0 !important;
  position: absolute !important;
  white-space: nowrap;
  width: 1px !important;
}

.custom-select {
  min-width: 0;
  position: relative;
}

label .custom-select {
  width: 100%;
}

.custom-select.open {
  z-index: 80;
}

.custom-select-trigger {
  background: #ffffff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-weight: 700;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 14px;
  width: 100%;
}

.custom-select-trigger:hover:not(:disabled) {
  background: #f8fbfd;
  border-color: var(--accent);
  color: var(--text);
}

.custom-select-trigger:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.15);
  outline: none;
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
}

.custom-select-icon {
  border-bottom: 2px solid currentColor;
  border-right: 2px solid currentColor;
  flex: 0 0 auto;
  height: 9px;
  margin-left: 12px;
  opacity: 0.7;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.18s ease;
  width: 9px;
}

.custom-select.open .custom-select-icon {
  transform: rotate(225deg) translateY(-2px);
}

.custom-select.disabled {
  opacity: 0.58;
}

.custom-select-menu {
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(21, 94, 117, 0.16);
  display: grid;
  gap: 4px;
  left: 0;
  margin-top: 6px;
  max-height: 280px;
  min-width: 100%;
  overflow: auto;
  padding: 6px;
  position: absolute;
  top: 100%;
}

.custom-select-menu[hidden] {
  display: none;
}

.custom-select-option {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  display: flex;
  font-size: 14px;
  font-weight: 700;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 10px;
  text-align: left;
  width: 100%;
}

.custom-select-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-option:hover:not(:disabled),
.custom-select-option:focus-visible {
  background: #f0fdfa;
  color: var(--accent-strong);
  outline: none;
}

.custom-select-option.selected {
  background: #ccfbf1;
  color: var(--accent-strong);
}

.custom-select-option.selected::after {
  content: "✓";
  color: var(--accent-strong);
  flex: 0 0 auto;
  margin-left: 12px;
}

.batch-bar {
  align-items: center;
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 14px;
  padding: 12px;
}

.selection-summary {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
}

.batch-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

label span {
  color: var(--text);
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

label input,
label select {
  width: 100%;
}

.wide-field {
  grid-column: 1 / -1;
}

.btn,
.link-btn,
button {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text-soft);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  gap: 8px;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  position: relative;
  text-decoration: none;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
}

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

.btn-primary:hover:not(:disabled),
.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.18);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text-soft);
}

.btn-secondary:hover:not(:disabled) {
  background: #f0fdfa;
  border-color: var(--accent);
  color: var(--accent-strong);
}

.btn-small {
  font-size: 13px;
  min-height: 34px;
  padding: 0 12px;
}

.btn-tiny {
  border-radius: 7px;
  font-size: 12px;
  min-height: 30px;
  padding: 0 9px;
}

.btn-danger {
  background: #fff7f7;
  border-color: #fecaca;
  color: var(--red);
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--red);
}

button:disabled,
.btn:disabled {
  background: #f2f5f7;
  color: #9aa8b6;
  cursor: not-allowed;
  opacity: 1;
  transform: none;
}

.btn span,
button span {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.mono,
.card-code {
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
}

.result-grid,
.generate-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.generate-grid {
  align-items: end;
  grid-template-columns: minmax(250px, 0.8fr) minmax(130px, 160px) minmax(320px, 1.5fr);
}

.generate-grid button {
  align-self: end;
}

.generate-provider-field,
.generate-count-field,
.generate-note-field {
  min-width: 0;
}

.generate-provider-field .custom-select-trigger,
.generate-count-field input,
.generate-note-field input {
  min-height: 52px;
}

.catalog-choice {
  align-items: stretch;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(210px, auto);
}

.catalog-choice-grid {
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 74px;
  padding: 14px 16px;
}

.catalog-choice .btn {
  min-height: 74px;
  padding-inline: 26px;
}

.catalog-choice-grid span,
.catalog-pane h4 {
  color: var(--accent-strong);
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 5px;
}

.catalog-choice-grid strong {
  color: var(--text);
  display: block;
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.catalog-choice-grid small {
  color: var(--text-dim);
  display: block;
  font-size: 12px;
  margin-top: 4px;
}

.manual-fields {
  background: #f8fbfd;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 12px;
}

.manual-fields summary {
  color: var(--text-soft);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.manual-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.price-tier-box,
.fallback-box {
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.price-tier-header {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.price-tier-header h3 {
  color: var(--accent-strong);
  font-size: 17px;
  margin-bottom: 5px;
}

.price-tier-header p,
.fallback-picker input {
  color: var(--text-soft);
  font-size: 14px;
}

.price-tier-header p[data-kind="ok"] { color: var(--green); }
.price-tier-header p[data-kind="warn"] { color: var(--orange); }
.price-tier-header p[data-kind="error"] { color: var(--red); }

.price-tier-list,
.fallback-country-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.fallback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.fallback-selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fallback-selected-list .catalog-empty {
  min-height: 72px;
  width: 100%;
}

.fallback-chip {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: inline-flex;
  gap: 10px;
  justify-content: space-between;
  min-height: 38px;
  min-width: min(240px, 100%);
  padding: 8px 10px;
}

.fallback-chip:hover {
  background: #fff7f7;
  border-color: #fecaca;
}

.fallback-chip.active {
  background: #ecfdf5;
  border-color: var(--accent);
}

.fallback-chip strong {
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.fallback-chip span {
  color: var(--red);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
}

.price-tier,
.fallback-country {
  align-items: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  justify-content: stretch;
  min-height: auto;
  padding: 12px;
  text-align: left;
  white-space: normal;
}

.price-tier:hover,
.fallback-country:hover,
.price-tier.active,
.fallback-country.active {
  background: #ecfdf5;
  border-color: var(--accent);
}

.price-tier.unavailable {
  background: #f8fafc;
  color: var(--text-dim);
}

.price-tier strong,
.fallback-country strong {
  color: var(--text);
  font-size: 16px;
}

.price-tier span,
.price-tier small,
.fallback-country small {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.35;
}

.status {
  margin-top: 12px;
}

.status[data-kind="error"] { color: var(--red); }
.status[data-kind="ok"] { color: var(--green); }
.status[data-kind="warn"] { color: var(--orange); }

.notice {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  color: var(--accent-strong);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.alert {
  background: #ffffff;
  border: 1px solid;
  border-radius: 8px;
  display: none;
  margin-bottom: 18px;
  padding: 13px 16px;
}

.alert.show { display: block; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: var(--green); }
.alert-error { background: #fef2f2; border-color: #fecaca; color: var(--red); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: var(--orange); }

.badge,
.table-status {
  align-items: center;
  background: #eef8ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: var(--blue);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  min-height: 30px;
  padding: 5px 12px;
}

.badge.ok,
.table-status.valid {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--green);
}

.badge.warn,
.table-status.redeemed {
  background: #fffbeb;
  border-color: #fde68a;
  color: var(--orange);
}

.badge.danger,
.table-status.invalid,
.table-status.disabled {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--red);
}

.table-status.deleted {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #64748b;
}

.message-list {
  display: grid;
  gap: 12px;
}

.message {
  background: #f8fbfd;
  box-shadow: none;
  padding: 16px;
}

.message strong {
  color: var(--green);
  display: block;
  font-size: 28px;
  margin-bottom: 8px;
}

.message p {
  color: var(--text-soft);
  line-height: 1.55;
  margin-top: 5px;
}

.empty {
  background: #f8fbfd;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 18px;
}

.code-output {
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: "Courier New", monospace;
  line-height: 1.55;
  margin-top: 16px;
  min-height: 100px;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
}

.generated-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 16px;
}

.generated-header span {
  color: var(--accent-strong);
  font-size: 15px;
  font-weight: 900;
}

.generated-header + .code-output {
  margin-top: 8px;
}

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

.pagination {
  align-items: center;
  color: var(--text-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 14px;
}

.pagination span {
  font-size: 14px;
  font-weight: 700;
}

table {
  background: #ffffff;
  border-collapse: collapse;
  min-width: 1100px;
  width: 100%;
}

thead {
  background: #f1f8f7;
}

th {
  border-bottom: 1px solid var(--line);
  color: #0f766e;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  padding: 14px;
  text-align: left;
  text-transform: none;
}

td {
  border-bottom: 1px solid #edf3f5;
  color: var(--text-soft);
  font-size: 14px;
  padding: 14px;
}

tr { transition: background 0.18s ease; }
tr:hover { background: #f8fbfd; }
tr.selectable-row { cursor: pointer; }
tr.selected-row,
tr.selected-row:hover { background: #ecfdf5; }

.select-col {
  width: 48px;
}

.select-cell {
  text-align: center;
  width: 48px;
}

.row-check {
  accent-color: var(--accent);
  cursor: pointer;
  height: 18px;
  min-height: 18px;
  width: 18px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 260px;
}

.inline-error {
  background: #fef2f2;
  color: var(--red);
  font-weight: 700;
}

.detail-box {
  display: grid;
  gap: 18px;
}

.detail-section h3 {
  color: #0f766e;
  font-size: 17px;
  margin-bottom: 10px;
}

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

.mini-item {
  background: #f8fbfd;
  box-shadow: none;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.55;
  padding: 12px;
}

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

.binding-editor .manual-grid {
  margin-top: 0;
}

.detail-binding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.detail-price-list {
  margin-top: 12px;
}

.disabled-editor {
  opacity: 0.76;
}

.checkbox-row {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  min-height: 46px;
  padding: 0 4px;
  white-space: nowrap;
}

.checkbox-row input {
  accent-color: var(--accent);
  height: 18px;
  min-height: 18px;
  width: 18px;
}

.checkbox-row span {
  color: var(--text-soft);
  font-size: 14px;
  margin: 0;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  align-items: center;
  background: rgba(15, 32, 51, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 32, 51, 0.22);
  max-height: min(820px, calc(100vh - 48px));
  overflow: hidden;
  width: min(1120px, 100%);
}

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

.modal-header h3 {
  color: var(--accent-strong);
  font-size: 20px;
  margin-bottom: 4px;
}

.modal-header p,
.modal-footer span {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.45;
}

.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
}

.catalog-picker {
  display: grid;
  gap: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 520px;
}

.fallback-modal-card {
  width: min(760px, 100%);
}

.fallback-picker {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 520px;
}

.catalog-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.catalog-pane + .catalog-pane {
  border-left: 1px solid var(--line);
}

.catalog-pane-head {
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.catalog-pane-head input {
  width: 100%;
}

.catalog-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding: 12px;
}

.fallback-picker .fallback-country-list {
  align-content: start;
  max-height: 520px;
  overflow: auto;
  padding: 12px;
}

.catalog-option {
  align-items: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 5px;
  justify-content: stretch;
  min-height: auto;
  padding: 11px 12px;
  text-align: left;
  white-space: normal;
  width: 100%;
}

.catalog-option:hover,
.catalog-option.active {
  background: #ecfdf5;
  border-color: var(--accent);
  color: var(--accent-strong);
}

.catalog-option strong {
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.catalog-option small {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.catalog-empty {
  align-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--text-dim);
  display: flex;
  min-height: 120px;
  padding: 16px;
}

@media (max-width: 768px) {
  body {
    padding: 18px 14px;
  }

  body.centered {
    align-items: flex-start;
  }

  .header {
    margin-bottom: 22px;
  }

  .header h1 {
    font-size: 32px;
  }

  .header p {
    font-size: 14px;
  }

  .card,
  .panel {
    padding: 24px 18px;
  }

  .inline-form,
  .actions,
  .data-header,
  .generated-header,
  .detail-binding-actions,
  .fallback-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .batch-bar,
  .batch-actions {
    align-items: stretch;
    flex-direction: column;
  }

	  .result-grid,
	  .generate-grid {
	    grid-template-columns: 1fr;
	  }

  .catalog-choice,
  .catalog-choice-grid,
  .manual-grid,
  .catalog-picker {
    grid-template-columns: 1fr;
  }

	  .catalog-choice {
	    grid-column: auto;
	  }

	  .catalog-choice .btn {
	    min-height: 46px;
	  }

  .catalog-pane + .catalog-pane {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .modal {
    align-items: stretch;
    padding: 12px;
  }

  .modal-card {
    max-height: calc(100vh - 24px);
  }

  .modal-header,
  .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .catalog-picker,
  .fallback-picker {
    min-height: 0;
  }

  .catalog-list,
  .fallback-picker .fallback-country-list {
    max-height: 260px;
  }

	  .btn,
	  button,
	  .inline-form input,
	  .inline-form select,
	  .inline-form .custom-select {
	    width: 100%;
	  }

  th,
  td {
    min-width: 120px;
  }
}

/* ---------- 后台登录 ---------- */

.login-view {
  align-items: center;
  animation: fadeIn 0.35s ease;
  display: flex;
  flex-direction: column;
  gap: 18px;
  justify-content: center;
  min-height: calc(100vh - 48px);
}

/* 本段写在 .hidden 之后，同优先级下会覆盖它，这里显式补上。 */
.login-view.hidden {
  display: none;
}

.login-card {
  backdrop-filter: blur(6px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(21, 94, 117, 0.16);
  max-width: 400px;
  padding: 34px 32px 28px;
  width: 100%;
}

.login-card.shake {
  animation: loginShake 0.4s ease;
}

.login-brand {
  align-items: center;
  display: flex;
  gap: 14px;
  margin-bottom: 26px;
}

.login-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 12px;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.28);
  color: #ffffff;
  display: inline-flex;
  flex: none;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.login-brand h1 {
  color: var(--accent-strong);
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.login-brand p {
  color: var(--text-soft);
  font-size: 14px;
  margin-top: 2px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-label {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.password-box {
  position: relative;
}

.password-box input {
  padding-right: 72px;
  width: 100%;
}

.password-toggle {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  min-height: 34px;
  padding: 0 12px;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.login-caps {
  color: var(--orange);
  font-size: 13px;
  font-weight: 700;
  margin-top: -4px;
}

.login-remember {
  align-items: center;
  color: var(--text-soft);
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  gap: 8px;
  user-select: none;
  width: fit-content;
}

.login-remember input {
  accent-color: var(--accent);
  height: 16px;
  min-height: 16px;
  padding: 0;
  width: 16px;
}

.login-submit {
  margin-top: 4px;
  width: 100%;
}

.login-submit:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.login-submit.is-loading span::before {
  animation: loginSpin 0.7s linear infinite;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  border-top-color: #ffffff;
  content: "";
  display: inline-block;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  width: 14px;
}

.login-status {
  font-size: 14px;
  line-height: 1.5;
  min-height: 21px;
  text-align: center;
}

.login-status[data-kind="error"] { color: var(--red); }
.login-status[data-kind="ok"] { color: var(--green); }
.login-status[data-kind="warn"] { color: var(--orange); }

.login-footnote {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}

/* 给密码管理器用的隐藏用户名，不能用 display:none，否则部分密码管理器会忽略它。 */
.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.workspace-bar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

.session-info {
  color: var(--text-soft);
  font-size: 14px;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

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

@media (max-width: 480px) {
  .login-card {
    padding: 26px 20px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-card.shake,
  .login-submit.is-loading span::before {
    animation: none;
  }
}

/* ---------- 后台外框：紧凑顶部导航 ---------- */

body.admin-page {
  padding: 0;
}

body.admin-page .login-view {
  min-height: 100vh;
  padding: 24px;
}

.admin-shell.hidden {
  display: none;
}

.admin-topbar {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.admin-topbar-inner {
  align-items: center;
  display: flex;
  gap: 20px;
  margin: 0 auto;
  max-width: 1400px;
  min-height: 64px;
  padding: 10px 24px;
}

.admin-brand {
  align-items: center;
  display: flex;
  flex: none;
  gap: 10px;
}

.admin-brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 9px;
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.25);
  color: #ffffff;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.admin-brand-name {
  color: var(--accent-strong);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.admin-nav {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.admin-nav::-webkit-scrollbar {
  display: none;
}

.admin-nav .tab-button {
  font-size: 14px;
  min-height: 38px;
  padding: 0 14px;
}

.admin-session {
  align-items: center;
  display: flex;
  flex: none;
  gap: 12px;
}

.admin-session .session-info {
  font-size: 13px;
  white-space: nowrap;
}

.admin-main {
  padding: 4px 24px 44px;
}

/* ---------- 表格可读性 ---------- */

.table-status,
.level-badge {
  white-space: nowrap;
}

.cards-table th,
.log-table th,
.detail-table th {
  white-space: nowrap;
}

.cards-table td.mono {
  white-space: nowrap;
}

.row-actions {
  flex-wrap: nowrap;
  min-width: 0;
}

.nowrap {
  white-space: nowrap;
}

.table-empty {
  color: var(--text-dim);
  padding: 40px 14px;
  text-align: center;
}

/* ---------- 操作日志 ---------- */

.log-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.log-chip {
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  min-height: 36px;
  padding: 0 8px 0 14px;
}

.log-chip-count {
  background: #eef4f4;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 20px;
  min-width: 26px;
  padding: 0 7px;
  text-align: center;
}

.log-chip.is-empty {
  opacity: 0.55;
}

.log-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  opacity: 1;
}

.log-chip.active .log-chip-count {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.log-filter {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(240px, 2fr) minmax(170px, 1fr) minmax(130px, 150px) auto auto;
  margin-bottom: 16px;
}

.log-filter input[type="search"],
.log-filter select {
  min-width: 0;
  width: 100%;
}

.log-problem-toggle {
  min-height: 46px;
}

.log-table {
  min-width: 980px;
}

.log-table td,
.detail-table td {
  vertical-align: top;
}

#log-body.is-loading {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.log-time {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.log-detail {
  color: var(--text);
  line-height: 1.55;
  min-width: 260px;
  word-break: break-word;
}

.log-ip {
  white-space: nowrap;
}

.log-muted {
  color: var(--text-dim);
}

.log-card {
  white-space: nowrap;
}

.log-card-link {
  background: none;
  border: none;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
  min-height: 0;
  padding: 0;
  text-decoration: underline dotted rgba(15, 118, 110, 0.45);
  text-underline-offset: 3px;
}

.log-card-link:hover {
  background: none;
  color: var(--accent);
}

.level-badge {
  align-items: center;
  background: #eef8ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: var(--blue);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  min-height: 26px;
  padding: 3px 10px;
}

.level-badge.success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--green);
}

.level-badge.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: var(--orange);
}

.level-badge.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--red);
}

/* ---------- 卡密详情 ---------- */

.detail-table {
  min-width: 640px;
}

.detail-code {
  color: var(--accent-strong);
  font-size: 16px;
  letter-spacing: 0.08em;
}

.detail-empty {
  background: #f8fbfd;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  padding: 16px;
  text-align: center;
}

.detail-section-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.detail-section-head h3 {
  margin-bottom: 0;
}

.binding-section > summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  list-style: none;
  margin-bottom: 10px;
}

.binding-section > summary::-webkit-details-marker {
  display: none;
}

.binding-section > summary h3 {
  margin-bottom: 0;
}

.binding-section > summary::after {
  color: var(--text-dim);
  content: "展开";
  font-size: 13px;
  margin-left: auto;
}

.binding-section[open] > summary::after {
  content: "收起";
}

.binding-locked {
  background: #f1f5f9;
  border-radius: 999px;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
}

@media (max-width: 1100px) {
  .admin-topbar-inner {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .admin-nav {
    flex-basis: 100%;
    order: 3;
  }

  .admin-session {
    margin-left: auto;
  }

  .log-filter {
    grid-template-columns: 1fr 1fr;
  }

  .log-filter input[type="search"] {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .admin-topbar-inner,
  .admin-main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .admin-session .session-info {
    display: none;
  }
}

/* 旧的窄屏规则把所有 .btn / button 设成 width: 100%。以下组件需要保持内容宽度：
   导航标签、分类筛选、行内操作，尤其是登录页里绝对定位在密码框上的显示/隐藏按钮，
   它被拉满后会整个盖住密码框，手机上点不进输入框。 */
@media (max-width: 768px) {
  .admin-nav .tab-button,
  .admin-session .btn,
  .log-chip,
  .log-card-link,
  .row-actions .btn,
  .detail-section-head .btn,
  .password-toggle {
    width: auto;
  }

  .log-problem-toggle {
    justify-content: flex-start;
  }

  .log-filter .btn {
    width: 100%;
  }
}

/* 网格列默认按内容最小宽度撑开：表格 min-width 980~1100px 会把整个面板撑出屏幕，
   手机上整页被撑宽再缩小显示。限定列宽后，宽表格只在自己的 .table-wrap 里横向滚动。 */
.workspace {
  grid-template-columns: minmax(0, 1fr);
}
