:root {
  --bg: #f2f0ea;
  --panel: #ffffff;
  --ink: #18202e;
  --muted: #5d6573;
  --line: #d9d5ca;
  --brand: #1d3fc4;
  --brand-ink: #ffffff;
  --rule: #3f8f2c;
  --topbar: #141c2b;
  --error: #c0262d;
  --warn: #b26a00;
  --ok: #2e7d32;
  --info: #3d5a98;
  --field: #fbfaf7;
  --mark: #fff1a8;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161e;
    --panel: #1b212c;
    --ink: #e8eaef;
    --muted: #9aa3b2;
    --line: #313949;
    --brand: #6f8cff;
    --brand-ink: #0d1220;
    --topbar: #0b0f16;
    --field: #151a23;
    --error: #ff7b7f;
    --warn: #f0b04a;
    --ok: #7fcf84;
    --info: #9db4ff;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12161e;
  --panel: #1b212c;
  --ink: #e8eaef;
  --muted: #9aa3b2;
  --line: #313949;
  --brand: #6f8cff;
  --brand-ink: #0d1220;
  --topbar: #0b0f16;
  --field: #151a23;
  --error: #ff7b7f;
  --warn: #f0b04a;
  --ok: #7fcf84;
  --info: #9db4ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 "Noto Sans KR", "Malgun Gothic", sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--topbar);
  color: #f3f4f7;
  border-bottom: 4px solid var(--rule);
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -0.02em; }
.brand p { margin: 0; font-size: 13px; color: #b9c0cc; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #2447d6;
  color: #fff;
  font-weight: 900;
  font-size: 20px;
}

.drafts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.drafts label { color: #b9c0cc; }
.drafts select { max-width: 260px; }
.topbar .btn { background: #232d40; color: #f3f4f7; border-color: #3a4660; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.step h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.step h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.step h3 { margin: 20px 0 6px; font-size: 15px; }
.num {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 14px;
}

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row select { flex: 1; min-width: 160px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-bottom: 12px; }
.grid label, .contacts { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.grid .wide { grid-column: 1 / -1; }
.sub { font-weight: 400; color: var(--muted); }

input, select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type="radio"] { width: auto; }
input.found, textarea.found { background: color-mix(in srgb, var(--mark) 55%, var(--field)); }

.choice { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.choice legend { font-size: 13px; font-weight: 700; padding: 0 4px; }
.choice label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.choice .inline input { width: 70px; }
.choice .inline.wide { flex: 1; min-width: 200px; }
.choice .inline.wide input { width: 100%; }

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 11px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 12px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
}
.drop strong { color: var(--ink); }
.drop.over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.paste { margin-top: 10px; }
.paste summary { cursor: pointer; font-size: 14px; color: var(--brand); }
.paste textarea { margin: 8px 0; }

.status { min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.status.error { color: var(--error); }
.status.ok { color: var(--ok); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks li { padding: 8px 10px 8px 34px; border-radius: 6px; position: relative; font-size: 14px; background: var(--field); border: 1px solid var(--line); }
.checks li::before { position: absolute; left: 10px; top: 8px; font-weight: 900; }
.checks .error { border-color: var(--error); }
.checks .error::before { content: "!"; color: var(--error); }
.checks .warn::before { content: "△"; color: var(--warn); }
.checks .info::before { content: "i"; color: var(--info); left: 14px; }
.checks .ok::before { content: "✓"; color: var(--ok); }

.export { display: flex; flex-wrap: wrap; gap: 8px; }
.howto { font-size: 13px; color: var(--muted); border-left: 3px solid var(--rule); padding-left: 10px; margin-top: 12px; }
.howto p { margin: 4px 0; }
code { background: var(--field); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 13px; }

.photos { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; display: grid; gap: 4px; }
.photos li { display: flex; justify-content: space-between; gap: 8px; }
.photos .small { color: var(--error); }

.guide ul { margin: 0; padding-left: 20px; font-size: 14px; }
.guide li { margin: 4px 0; }

/* ---------- 표 편집 · 목록 ---------- */

.combo, .pair { display: flex; gap: 4px; }
.combo input { flex: 1; min-width: 0; }
.pair select { flex: 1; min-width: 0; }
.combo-btn {
  flex: none;
  width: 34px;
  font: inherit;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--brand);
  cursor: pointer;
}
.combo-btn:hover { border-color: var(--brand); }
.table-editor { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 0 0 12px; }
.table-editor legend { font-size: 13px; font-weight: 700; padding: 0 4px; }
.contacts-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin: 4px 0 4px; }
.contact-row { display: grid; grid-template-columns: 0.8fr 1fr 1.4fr 34px 34px; gap: 4px; margin-bottom: 4px; }
.contact-row input { min-width: 0; }
.btn.small { font-size: 13px; padding: 4px 10px; }

.combo-menu {
  position: fixed;
  z-index: 50;
  overflow: auto;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 6px;
  font-size: 14px;
}
.combo-title { font-size: 12px; color: var(--muted); padding: 2px 6px 6px; }
.combo-empty { color: var(--muted); padding: 6px; }
.combo-item { display: flex; align-items: center; border-radius: 6px; }
.combo-item:hover { background: var(--field); }
.combo-item button, .combo-save {
  font: inherit;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  padding: 7px 8px;
}
.combo-item button:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.combo-del { color: var(--muted); font-weight: 700; }
.combo-del:hover { color: var(--error); }
.combo-save { width: 100%; margin-top: 4px; border-top: 1px solid var(--line); color: var(--brand); font-weight: 600; }
.combo-save:disabled { color: var(--muted); cursor: default; font-weight: 400; }

/* ---------- 미리 보기 ---------- */

.preview-wrap { position: sticky; top: 16px; align-self: start; }
.preview-bar { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.paper-scroll { max-height: calc(100vh - 60px); overflow: auto; border-radius: 4px; }

.paper {
  background: #fff;
  color: #000;
  width: 100%;
  max-width: 794px;
  min-height: 1000px;
  margin: 0 auto;
  padding: 48px 52px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
  font-family: "휴먼명조", "HCR Batang", "Noto Serif KR", serif;
  overflow-wrap: anywhere;
}
.paper mark { background: #ffe066; color: #000; }

/* ---------- dialog ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  width: min(620px, calc(100vw - 32px));
  padding: 20px 22px;
}
dialog::backdrop { background: rgba(10, 14, 22, 0.55); }
dialog h2 { margin: 0; }
.contacts { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 12px; margin: 0 0 12px; }
.contact { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 6px; }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-row img { height: 40px; width: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.dialog-actions .spacer { flex: 1; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .preview-wrap { position: static; }
  .paper-scroll { max-height: none; overflow-x: auto; }
  .paper { padding: 28px 22px; min-height: 0; }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 16px; }
  .grid { grid-template-columns: 1fr; }
  .contact-row { grid-template-columns: 1fr 1fr 34px 34px; }
  .contact-row input[data-cf="phone"] { grid-column: 1 / 3; grid-row: 2; }
}

@media print {
  @page { size: A4; margin: 15mm 15mm 15mm 15mm; }
  body { background: #fff; }
  .topbar, .steps, .preview-bar, dialog { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .paper-scroll { max-height: none; overflow: visible; }
  .paper { box-shadow: none; padding: 0; max-width: none; min-height: 0; }
  .paper mark { background: none; }
}
