:root {
  color-scheme: light;
  --ink: #151816;
  --muted: #697069;
  --paper: #f2f3ed;
  --surface: #fcfdf8;
  --line: #c8ccc3;
  --accent: #b8f238;
  --blue: #3156d3;
  --danger: #c9362b;
  --warning: #d88418;
  font-family: "Avenir Next", "Noto Sans SC", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--ink);
  background: var(--surface);
}

.brand-block, .target-block { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: var(--ink);
  color: var(--accent);
  font: 800 16px/1 ui-monospace, monospace;
}
.kicker, .step, .meta-label { margin: 0; font: 700 11px/1.2 ui-monospace, monospace; color: var(--muted); }
h1, h2 { margin: 3px 0 0; font-weight: 700; letter-spacing: 0; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
.signal { flex: 0 0 10px; width: 10px; height: 10px; background: var(--accent); border: 1px solid var(--ink); }
.target-block strong { display: block; margin-top: 4px; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; font-size: 13px; white-space: nowrap; }

main { width: min(1460px, 100%); margin: 0 auto; }
.control-band {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 22px;
  align-items: end;
  padding: 22px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
}
.target-field, .notes-field { grid-column: span 5; }
.admin-field, .group-field { grid-column: span 4; }
.token-field, .defaults { grid-column: span 3; }
body.link-authenticated .target-field, body.link-authenticated .admin-field { grid-column: span 6; }
.field { display: grid; gap: 7px; }
.field > span { font: 700 12px/1 ui-monospace, monospace; color: var(--muted); }
.field input, .field select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  padding: 0 12px;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus, textarea:focus { border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.group-control { display: grid; grid-template-columns: minmax(0, 1fr) 64px; }
.group-control select { min-width: 0; border-right: 0; appearance: none; }
.group-control button { border: 1px solid var(--ink); border-radius: 0; background: var(--ink); color: white; font-weight: 700; }
.group-control button:hover { background: var(--blue); }
.group-control button:disabled { cursor: wait; background: #a8aca5; border-color: #a8aca5; }
.admin-token-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.admin-token-control input { min-width: 0; border-right: 0; }
.admin-token-control output { display: grid; place-items: center; min-width: 142px; border: 1px solid var(--ink); background: var(--ink); color: var(--accent); padding: 0 10px; font: 700 11px/1 ui-monospace, monospace; }
.defaults { display: flex; flex-wrap: wrap; gap: 5px; padding-bottom: 2px; }
.defaults span { padding: 9px 10px; border: 1px solid var(--ink); background: var(--surface); font: 700 11px/1 ui-monospace, monospace; }
.defaults span:last-child { background: var(--accent); }

.workspace { display: block; }
.input-pane, .review-pane { padding: 30px clamp(20px, 4vw, 64px) 36px; }
.input-pane { border-bottom: 1px solid var(--ink); }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 22px; }
.quiet-button { border: 0; border-bottom: 1px solid var(--ink); background: transparent; padding: 5px 0; font-size: 12px; }
.paste-field { display: block; }
textarea {
  width: 100%;
  height: 320px;
  resize: vertical;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  padding: 18px;
  color: var(--ink);
  outline: none;
  font: 13px/1.7 ui-monospace, "SFMono-Regular", monospace;
}
.mapping-list { display: grid; gap: 6px; margin-top: 14px; }
.mapping-line { display: grid; grid-template-columns: 120px auto minmax(0, 1fr); align-items: start; gap: 12px; font: 12px/1.2 ui-monospace, monospace; }
.mapping-line .arrow { color: var(--blue); }
.mapping-line strong { overflow-wrap: anywhere; }
.counter { display: flex; align-items: baseline; gap: 6px; }
.counter strong { font: 800 34px/1 ui-monospace, monospace; }
.counter span { font-size: 12px; color: var(--muted); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: var(--surface); }
.summary-grid > div { padding: 13px; border-right: 1px solid var(--line); }
.summary-grid > div:last-child { border-right: 0; }
.summary-grid span, .summary-grid strong { display: block; }
.summary-grid span { font-size: 11px; color: var(--muted); }
.summary-grid strong { margin-top: 6px; font: 700 17px/1 ui-monospace, monospace; }
.preview-list { height: 280px; margin: 14px 0; overflow: auto; border-top: 1px solid var(--line); }
.preview-row, .result-row { display: grid; align-items: center; gap: 12px; min-height: 46px; border-bottom: 1px solid var(--line); }
.preview-row { grid-template-columns: 32px minmax(0, 1fr) auto; }
.preview-row .index { font: 11px/1 ui-monospace, monospace; color: var(--muted); }
.preview-row .identity { min-width: 0; }
.preview-row strong, .preview-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-row strong { font-size: 13px; }
.preview-row small { margin-top: 3px; color: var(--muted); }
.badge { padding: 5px 7px; border: 1px solid currentColor; font: 700 10px/1 ui-monospace, monospace; }
.badge.valid { color: #366c00; background: #edffd2; }
.badge.invalid { color: var(--danger); background: #fff0ee; }
.badge.duplicate { color: var(--warning); background: #fff6e3; }
.empty-state { display: grid; place-items: center; height: 100%; color: var(--muted); font: 12px/1 ui-monospace, monospace; }
.submit-button { width: 100%; height: 52px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--ink); border-radius: 0; background: var(--ink); color: white; padding: 0 18px; font-weight: 700; }
.submit-button:not(:disabled):hover { background: var(--blue); }
.submit-button:disabled { cursor: not-allowed; background: #a8aca5; border-color: #a8aca5; }

.results-band { padding: 30px clamp(20px, 4vw, 64px) 50px; border-top: 1px solid var(--ink); background: var(--surface); }
.result-summary { margin: 0; font: 12px/1.5 ui-monospace, monospace; color: var(--muted); }
.results-list { border-top: 1px solid var(--ink); }
.result-row { grid-template-columns: 110px minmax(0, 1fr) 90px; }
.result-row .result-type { font: 700 11px/1 ui-monospace, monospace; }
.result-row.created .result-type { color: #366c00; }
.result-row.existing .result-type { color: var(--warning); }
.result-row.failed .result-type { color: var(--danger); }
.result-row span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; }
.result-row code { text-align: right; color: var(--muted); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; max-width: min(420px, calc(100vw - 44px)); padding: 13px 16px; border: 1px solid var(--ink); background: var(--ink); color: white; transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 900px) {
  .control-band { grid-template-columns: 1fr 1fr; }
  .target-field, .notes-field, .admin-field, .group-field, .token-field { grid-column: auto; }
  body.link-authenticated .target-field, body.link-authenticated .admin-field { grid-column: auto; }
  .defaults { grid-column: 1 / -1; }
  textarea { height: 330px; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; gap: 12px; }
  .brand-block { gap: 10px; }
  .brand-mark { width: 46px; height: 46px; }
  .brand-block h1 { font-size: 20px; white-space: nowrap; }
  .target-block { max-width: 43%; }
  .target-block strong { max-width: 100%; }
  .control-band { grid-template-columns: 1fr; }
  .target-field, .notes-field, .admin-field, .group-field, .token-field, .defaults { grid-column: auto; }
  .defaults { flex-wrap: wrap; }
  .input-pane, .review-pane, .results-band { padding-left: 18px; padding-right: 18px; }
  .result-row { grid-template-columns: 78px minmax(0, 1fr); padding: 9px 0; }
  .result-row code { grid-column: 2; text-align: left; }
  .admin-token-control { grid-template-columns: 1fr; }
  .admin-token-control input { border-right: 1px solid var(--line); }
  .admin-token-control output { min-height: 34px; }
}
