:root {
  --bg: #f5f5f7;
  --paper: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #8e8e93;
  --line: rgba(29, 29, 31, .1);
  --blue: #0071e3;
  --green: #248a3d;
  --red: #d70015;
  --orange: #b25000;
  --r: 18px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(60% 34% at 12% 0%, rgba(255, 59, 48, .07), transparent 70%),
    radial-gradient(50% 30% at 48% 0%, rgba(255, 204, 0, .07), transparent 70%),
    radial-gradient(50% 32% at 84% 0%, rgba(0, 113, 227, .08), transparent 70%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
[hidden] { display: none !important; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  min-height: 54px; padding: 10px max(18px, env(safe-area-inset-left)) 10px max(18px, env(safe-area-inset-right));
  border-bottom: 1px solid rgba(29, 29, 31, .07);
  background: rgba(250, 250, 252, .8);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.back { color: var(--ink-2); text-decoration: none; font-size: 12px; white-space: nowrap; }
.back:hover { color: var(--ink); }
.top-title { font-size: 13px; font-weight: 650; letter-spacing: .01em; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.quiet { color: var(--ink-3); text-decoration: none; font-size: 11.5px; }
.quiet:hover { color: var(--ink); }

.layout {
  display: grid; grid-template-columns: 292px minmax(0, 1fr);
  gap: 18px; width: min(1240px, 100%); margin: 0 auto;
  padding: 20px max(18px, env(safe-area-inset-left)) 40px max(18px, env(safe-area-inset-right));
  align-items: start;
}

.picker {
  position: sticky; top: 74px; min-width: 0;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 96px);
  padding: 12px; border: 1px solid rgba(255, 255, 255, .7);
  border-radius: var(--r); background: rgba(255, 255, 255, .76);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.search-wrap { display: block; min-width: 0; margin-bottom: 10px; }
.search-wrap input {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .8); outline: none;
}
.search-wrap input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, .12); }
.record-list { min-width: 0; overflow: auto; overscroll-behavior: contain; padding-right: 2px; }
.record-item {
  display: block; width: 100%; min-width: 0; margin: 0 0 5px; padding: 9px 10px;
  border: 1px solid transparent; border-radius: 11px;
  background: transparent; text-align: left; cursor: pointer;
}
.record-item:hover { background: rgba(0, 0, 0, .035); }
.record-item.active { border-color: rgba(0, 113, 227, .24); background: rgba(0, 113, 227, .08); }
.record-seq { display: block; color: var(--ink-3); font-size: 9.5px; letter-spacing: .08em; }
.record-title {
  display: block; min-width: 0; margin-top: 1px; font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.record-sub {
  display: block; min-width: 0; margin-top: 1px; color: var(--ink-3); font-size: 10.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.record-status {
  display: inline-block; margin-top: 3px; padding: 1px 6px;
  border-radius: 999px; background: rgba(0, 0, 0, .05);
  color: var(--ink-3); font-size: 9.5px;
}
.record-status.approved { background: rgba(36, 138, 61, .1); color: var(--green); }
.record-status.pending { background: rgba(178, 80, 0, .1); color: var(--orange); }
.record-status.rejected { background: rgba(215, 0, 21, .1); color: var(--red); }

.editor {
  min-width: 0; padding: 20px 22px 22px;
  border: 1px solid rgba(255, 255, 255, .8); border-radius: 22px;
  background: rgba(255, 255, 255, .9); box-shadow: var(--shadow);
}
.editor-head { display: flex; align-items: flex-start; gap: 12px; }
.editor-head h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }
.meta { margin: 4px 0 0; color: var(--ink-2); font-size: 11px; }
.badge {
  margin-left: auto; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 149, 0, .12); color: #9a5300;
  font-size: 10px; white-space: nowrap;
}

.tabs {
  display: inline-flex; gap: 2px; margin-top: 16px; padding: 3px;
  border-radius: 10px; background: rgba(0, 0, 0, .05);
}
.tab {
  padding: 5px 13px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-2); font-size: 11.5px; cursor: pointer;
}
.tab.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.pane { margin-top: 12px; }
.hint { margin: 0 0 8px; color: var(--ink-3); font-size: 10.5px; line-height: 1.55; }

.group { margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(29, 29, 31, .07); }
.group:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.group h2 {
  margin: 0 0 12px; color: var(--ink-2);
  font-size: 10.5px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
}
.group-note { margin-left: 6px; color: var(--ink-3); font-weight: 400; letter-spacing: 0; text-transform: none; }

.field { margin-bottom: 12px; }
.field > label {
  display: block; margin-bottom: 4px;
  color: var(--ink-2); font-size: 10.5px; letter-spacing: .02em;
}
.req { color: var(--red); }
.field input:not([type="checkbox"]), .field select, .field textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: rgba(251, 251, 253, .9); outline: none;
  font-size: 12px; line-height: 1.5;
}
.field textarea { resize: vertical; min-height: 68px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, .1);
  background: #fff;
}
.field .hint { margin-top: 4px; margin-bottom: 0; }
.field-checkbox { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.field-checkbox label { display: flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: 11.5px; }
.field-checkbox input { width: 15px; height: 15px; accent-color: var(--blue); }

.url-status { min-height: 16px; margin-top: 4px; color: var(--ink-3); font-size: 10.5px; }
.url-status.ok { color: var(--green); }
.url-status.err { color: var(--red); }
.canonical-btn {
  margin-top: 4px; padding: 3px 8px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--blue); font-size: 10px; cursor: pointer;
}

.custom-list { display: flex; flex-direction: column; gap: 7px; }
.custom-row {
  display: grid; grid-template-columns: minmax(110px, .9fr) 98px minmax(150px, 1.5fr) 42px;
  gap: 7px; align-items: start; padding: 8px;
  border: 1px solid var(--line); border-radius: 11px; background: rgba(250, 250, 252, .8);
}
.custom-row input, .custom-row select, .custom-row textarea {
  width: 100%; padding: 7px 8px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; outline: none; font-size: 11.5px;
}
.custom-row textarea { min-height: 70px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.custom-row input:focus, .custom-row select:focus, .custom-row textarea:focus { border-color: var(--blue); }
.custom-key { color: var(--ink-2); }
.custom-del {
  height: 32px; border: 0; border-radius: 8px; background: transparent;
  color: var(--red); font-size: 10.5px; cursor: pointer;
}
.custom-del:hover { background: rgba(215, 0, 21, .08); }
.custom-error { grid-column: 1 / -1; margin: -1px 0 0; color: var(--red); font-size: 10.5px; }
.custom-add { display: flex; gap: 7px; margin-top: 8px; }
.custom-add input {
  flex: 1; min-width: 0; height: 33px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; font-size: 11.5px;
}
.custom-add input:focus { border-color: var(--blue); }

.json-actions { margin-top: 8px; }
#jsonEditor {
  width: 100%; min-height: 420px; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fbfbfd; outline: none; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.55; tab-size: 2;
}
#jsonEditor:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, .1); }

.editor-actions, .preview-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.btn {
  min-height: 34px; padding: 6px 13px; border: 1px solid var(--line);
  border-radius: 9px; background: rgba(255, 255, 255, .85);
  color: var(--ink); font-size: 11.5px; cursor: pointer;
}
.btn:hover { background: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-accent { border-color: transparent; background: var(--blue); color: #fff; }
.btn-accent:hover { background: #0077ed; }
.btn-accent:disabled { background: var(--blue); }

.status {
  margin: 12px 0 0; padding: 8px 10px; border-radius: 9px;
  background: rgba(0, 113, 227, .08); color: #0055a8; font-size: 11px;
}
.status.err { background: rgba(215, 0, 21, .08); color: var(--red); }
.errors, .warnings { margin-top: 10px; padding: 9px 11px; border-radius: 10px; font-size: 10.5px; line-height: 1.55; }
.errors { background: rgba(215, 0, 21, .06); color: var(--red); }
.warnings { background: rgba(255, 149, 0, .08); color: #8a4d00; }
.msg + .msg { margin-top: 3px; }

.preview {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  width: min(560px, 100vw); padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-left: 1px solid var(--line); background: rgba(255, 255, 255, .98);
  box-shadow: -20px 0 50px rgba(0, 0, 0, .16);
}
.preview-head { display: flex; align-items: center; gap: 12px; }
.preview-head h2 { margin: 0; font-size: 16px; }
.preview-head .btn { margin-left: auto; }
.preview pre {
  flex: 1; min-height: 0; margin: 8px 0 0; padding: 12px;
  overflow: auto; border: 1px solid var(--line); border-radius: 12px;
  background: #fbfbfd; white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; line-height: 1.55;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .picker { position: static; max-height: 330px; }
  .record-list { max-height: 260px; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .top-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .layout { padding-left: 12px; padding-right: 12px; }
  .editor { padding: 16px 14px 18px; border-radius: 18px; }
  .custom-row { grid-template-columns: minmax(0, 1fr) 88px 40px; }
  .custom-value { grid-column: 1 / -1; }
  .custom-error { grid-column: 1 / -1; }
  .preview { width: 100vw; border-left: 0; }
}
