:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #17181a;
  --muted: #6b6f76;
  --line: #e2e2de;
  --line-strong: #c9c9c4;
  --accent: #17181a;
  --sample: #f6d70f;
  --po: #e3242b;
  --pink: #e8357e;
  --error: #c4231c;
  --error-bg: #fdf0ef;
  --ok: #1f7a4d;
  --warn: #9a6200;
  --radius: 10px;
  --radius-sm: 6px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; }
.loading { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: rgba(255,255,255,0.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; margin-right: auto; }
.brand-mark { width: 18px; height: 18px; border-radius: 4px; background: linear-gradient(135deg, var(--sample) 50%, var(--po) 50%); }
.editor-bar .title { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.editor-bar .title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #000; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #ececea; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: #ececea; color: var(--ink); }
.icon-btn.danger:hover { color: var(--error); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.linkish { background: none; border: 0; padding: 0 4px; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 12px; }
:focus-visible { outline: 2px solid #2b6cff; outline-offset: 2px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: #ececea; color: var(--muted); margin-left: 6px; }
.pill.ok { background: #e3f3ea; color: var(--ok); }
.mode-pill { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.mode-pill.sample { background: var(--sample); color: #111; }
.mode-pill.po { background: var(--po); color: #fff; }
.unsaved { font-size: 12px; }

.list-wrap { max-width: 1040px; margin: 32px auto; padding: 0 24px; display: grid; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.card h1 { margin: 0 0 16px; font-size: 22px; letter-spacing: -0.02em; }
.card h2 { margin: 0 0 16px; font-size: 16px; letter-spacing: -0.01em; }
.records { width: 100%; border-collapse: collapse; }
.records th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
.records td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.records tr.linked td:first-child { padding-left: 24px; }
.link-mark { color: var(--muted); }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { min-width: 74px; justify-content: center; }
.btn.danger { color: var(--error); } .btn.danger:hover { background: #fbeaea; }
.records tr.archived td { color: var(--muted); }
.initials { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: #ececea; color: var(--ink); font-size: 11px; font-weight: 700; letter-spacing: 0.02em; cursor: default; }
.archived-toggle { margin-top: 12px; }
.questions ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.questions code { font-size: 12px; background: #f1f1ee; padding: 1px 5px; border-radius: 4px; }

.editor { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 28px; max-width: 1180px; margin: 0 auto; padding: 24px; }
.toc { position: sticky; top: 76px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.toc a { text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.toc a:hover { background: #ececea; color: var(--ink); }
.toc .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--error); }
.form { display: grid; gap: 18px; min-width: 0; }
.section { scroll-margin-top: 80px; }
.section-workflow { border-top: 4px solid var(--line-strong); }
.section > .field, .section > .group { margin-bottom: 16px; }
.section > :last-child { margin-bottom: 0; }

.error-summary { display: flex; gap: 12px; background: var(--error-bg); border: 1px solid #f2c8c5; color: var(--error); border-radius: var(--radius); padding: 16px 18px; }
.error-summary ul { margin: 6px 0 0; padding-left: 18px; }
.error-summary a { color: var(--error); }

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.req { color: var(--error); font-weight: 700; }
.help { font-size: 12px; color: var(--muted); }
.error { font-size: 12px; color: var(--error); font-weight: 550; }
.has-error > input, .has-error > textarea, .has-error > select, .has-error .other-wrap select { border-color: var(--error); }
.group.has-error { outline: 1px solid var(--error); outline-offset: 6px; border-radius: 4px; }
.internal-tag { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #5b4bc4; background: #efedfb; padding: 1px 6px; border-radius: 4px; }
.confirm-tag { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--warn); background: #fff4dc; padding: 1px 6px; border-radius: 4px; cursor: help; }

input[type=text], input[type=number], input[type=date], input[type=password], select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 10px; background: #fff; width: 100%; max-width: 520px; }
textarea { resize: vertical; max-width: 680px; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(23,24,26,0.08); }
input[readonly] { background: #f6f6f4; color: var(--muted); }
.color-wrap { display: flex; gap: 8px; align-items: center; } .color-wrap .hex-input { max-width: 130px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.color-wrap input[type=color] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; cursor: pointer; flex: none; }
.has-error .color-wrap .hex-input { border-color: var(--error); }
.other-wrap { display: flex; gap: 8px; flex-wrap: wrap; } .other-wrap select { max-width: 200px; }
.locked { padding: 8px 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); color: var(--po); font-weight: 700; font-style: italic; font-size: 13px; max-width: 680px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; cursor: pointer; flex-wrap: wrap; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }

.radios { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.radio { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 6px 12px; cursor: pointer; font-weight: 550; font-size: 13px; }
.radio input { position: absolute; opacity: 0; pointer-events: none; }
.radio.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.radio:has(input:focus-visible) { outline: 2px solid #2b6cff; outline-offset: 2px; }
.mode-switch .radio { padding: 12px 22px; font-size: 15px; font-weight: 750; letter-spacing: 0.02em; }
.mode-switch .radio.sample.on { background: var(--sample); border-color: #c9ae00; color: #111; }
.mode-switch .radio.po.on { background: var(--po); border-color: #b31a20; color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px; font-weight: 550; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip:has(input:focus-visible) { outline: 2px solid #2b6cff; outline-offset: 2px; }
.chip-other { max-width: 240px !important; padding: 4px 10px !important; border-radius: 99px !important; font-size: 13px !important; }

.files { display: flex; flex-direction: column; gap: 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs:empty { display: none; }
.thumb { position: relative; margin: 0; width: 112px; }
.thumb img { width: 112px; height: 112px; object-fit: contain; background: #f6f6f4; border: 1px solid var(--line); border-radius: var(--radius-sm); display: block; }
.thumb figcaption { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.thumb .remove { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,0.92); border: 1px solid var(--line); }
.file-chip { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: 112px; height: 112px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f6f6f4; font-size: 11px; text-decoration: none; padding: 6px; text-align: center; word-break: break-all; }
.upload { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 7px 14px; cursor: pointer; font-weight: 550; font-size: 13px; }
.upload:hover { border-color: var(--ink); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload:has(input:focus-visible) { outline: 2px solid #2b6cff; outline-offset: 2px; }
.reuse { max-width: 320px !important; font-size: 13px; }

.position { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.pos-img { position: relative; cursor: crosshair; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f6f6f4; line-height: 0; }
.pos-img img { max-height: 200px; max-width: 220px; display: block; user-select: none; }
.marker { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--po); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--po); }
.pos-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }

.group { display: flex; flex-direction: column; gap: 10px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; }
.row-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfbfa; }
.row-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.row-tools { display: flex; gap: 2px; }
.row-fields { padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; }
.row-fields .type-textarea, .row-fields .type-file, .row-fields .type-position, .row-fields .type-multiselect { grid-column: 1 / -1; }
.group-actions { display: flex; gap: 8px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 550; transition: opacity .18s ease, transform .18s ease; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--error); } #toast.warn { background: #6d4600; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; padding: 16px; }
  .toc { display: none; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .list-wrap { padding: 0 16px; }
  .records th:nth-child(7), .records td:nth-child(7) { display: none; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login-card { display: flex; flex-direction: column; gap: 10px; }
.login-card .brand { margin: 0 0 8px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 6px; }
.login-card input { max-width: none; }
.login-card .btn { margin-top: 6px; justify-content: center; }
