:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-muted: #eef3f6;
  --ink: #162421;
  --muted: #5d6b66;
  --line: #d8e0dc;
  --green: #0f7a5a;
  --green-dark: #095c44;
  --blue: #1c5e86;
  --amber: #a85d10;
  --danger: #b3261e;
  --shadow: 0 22px 60px rgba(31, 49, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 122, 90, 0.1), transparent 260px),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
  gap: 24px;
  align-items: start;
}

.intro,
.generator,
.result-panel,
.records-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro {
  grid-column: 1 / -1;
  padding: 28px 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.intro-copy {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.generator {
  display: grid;
  gap: 22px;
  padding: 28px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.input-field > span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.fixed-code {
  display: inline-grid;
  min-width: 124px;
  height: 48px;
  place-items: center;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--blue);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.option-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}

.option {
  position: relative;
  min-height: 72px;
}

.option input,
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.option span {
  display: grid;
  gap: 6px;
  height: 100%;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.option strong {
  align-self: end;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.35;
}

.option small {
  align-self: start;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.option input:checked + span {
  border-color: var(--green);
  background: #edf8f4;
  box-shadow: inset 0 0 0 1px var(--green);
}

.option input:focus-visible + span,
.segmented input:focus-visible + span,
input:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(28, 94, 134, 0.26);
  outline-offset: 2px;
}

.input-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.9fr 0.8fr;
  gap: 16px;
  align-items: end;
}

.input-field input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.segmented label {
  position: relative;
  min-width: 0;
}

.segmented span {
  display: grid;
  height: 100%;
  place-items: center;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}

.segmented label:last-child span {
  border-right: 0;
}

.segmented input:checked + span {
  background: var(--green);
  color: #fff;
}

.message {
  min-height: 22px;
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.5;
}

.actions {
  display: flex;
  justify-content: flex-start;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  min-width: 160px;
  padding: 0 22px;
  background: var(--green);
  color: #fff;
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button {
  min-width: 96px;
  padding: 0 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--green-dark);
}

.secondary-button:hover {
  border-color: var(--green);
}

.result-panel {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 18px;
  padding: 28px;
}

.batch-code {
  display: block;
  width: 100%;
  min-height: 86px;
  padding: 18px;
  border: 1px dashed rgba(15, 122, 90, 0.45);
  border-radius: 8px;
  background: #f3fbf8;
  color: var(--green-dark);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  min-height: 48px;
  gap: 12px;
  align-items: center;
}

#copy-status {
  color: var(--amber);
  font-size: 14px;
  line-height: 1.5;
}

.storage-status {
  min-height: 22px;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.storage-status.ok {
  color: var(--green-dark);
}

.storage-status.warn {
  color: var(--amber);
}

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

.records-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 14px;
  padding: 28px;
}

.records-heading {
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
}

.compact-button {
  min-width: 78px;
  min-height: 38px;
}

.records-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.records-status.ok {
  color: var(--green-dark);
}

.records-status.warn {
  color: var(--amber);
}

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

.records-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
}

.records-table th,
.records-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.records-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

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

.record-code {
  color: var(--green-dark);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .workspace,
  .input-grid {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding: 20px 0;
  }

  .intro,
  .generator,
  .result-panel,
  .records-panel {
    padding: 20px;
  }

  .option-grid {
    grid-template-columns: 1fr;
  }

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

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .batch-code {
    font-size: 22px;
  }

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

  .compact-button {
    width: 100%;
  }

  .records-table-wrap {
    overflow-x: visible;
  }

  .records-table {
    min-width: 0;
  }

  .records-table thead {
    display: none;
  }

  .records-table,
  .records-table tbody,
  .records-table tr,
  .records-table td {
    display: block;
    width: 100%;
  }

  .records-table tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
  }

  .records-table tbody tr:last-child {
    border-bottom: 0;
  }

  .records-table td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 0;
  }

  .records-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
  }

  .records-table .empty-records {
    display: block;
  }

  .records-table .empty-records::before {
    content: "";
  }
}
