/* 펠릭스 웹 주문서 (/o/<token>) — 거래처 공개 주문 페이지 (밝은 톤 고정)
   레이아웃: 주문자·배송지 → 도어 세트(입력 | 도면) → 주문 전송. 좁은 화면(≤760px)에선 세트 카드 1열 */
@font-face {
  font-family: 'Pretendard';
  src: url('/fonts/Pretendard-Regular.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Pretendard';
  src: url('/fonts/Pretendard-Bold.ttf') format('truetype');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  /* 밝은 톤 고정 — 시스템 다크 모드와 무관하게 항상 밝게 표시 */
  color-scheme: light;
  --bg: #f7f9fc;
  --paper: #ffffff;
  --ink: #23303d;
  --muted: #66758a;
  --line: #dde4ec;
  --accent: #2f7ad0;
  --accent-soft: #edf4fd;
  --on-accent: #ffffff;
  --draw: #23303d;
  --dim: #2f7ad0;
  --danger: #d0453a;
  --danger-soft: #fdf0ef;
  --ok: #2f8a57;
  --ok-soft: #e8f4ed;
  --sw-white: #f4f4f2;
  --sw-silver: #b9bec4;
  --sw-black: #3b3d40;
  --shadow: rgba(20, 40, 70, 0.18);
  --backdrop: rgba(30, 45, 60, 0.35);
  --print-ink: #000000;
  --print-paper: #ffffff;
  /* DoorDrawing 도면 색상 */
  --door-line: var(--draw);
  --door-dim: var(--dim);
  --door-muted: var(--muted);
  --door-danger: var(--danger);
  --font-body: 'Pretendard', 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
  --font-num: ui-monospace, 'Cascadia Mono', 'Consolas', 'D2Coding', monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; overflow-x: hidden; }
[hidden] { display: none !important; }
.wrap { max-width: 1040px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 80px; display: grid; gap: 20px; min-width: 0; }
.wrap > * { min-width: 0; }
.form-stack { display: grid; gap: 20px; min-width: 0; }
.form-stack > * { min-width: 0; }

header.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
header.top h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; text-wrap: balance; }
header.top .who { font-size: 14px; color: var(--muted); }
header.top .who b { color: var(--ink); }

section.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 20px; display: grid; gap: 16px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-head .sub { font-size: 13px; color: var(--muted); }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=tel], input[type=number], textarea {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type=number] { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.bad { border-color: var(--danger); background: var(--danger-soft); }
textarea { resize: vertical; min-height: 60px; }

/* 배송지 */
.addr { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.addr-head { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
.check.small { font-size: 13px; color: var(--ink); }
.addr-hint { font-size: 12px; min-height: 1.5em; }

/* 세트 카드 */
.sets { display: grid; gap: 16px; }
.set { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-width: 0; }
.set-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 16px; background: var(--accent-soft); }
.set-head h3 { margin: 0; font-size: 15px; }
.set-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; padding: 16px; }
@media (max-width: 760px) { .set-body { grid-template-columns: minmax(0, 1fr); } }
.inputs { display: grid; gap: 14px; align-content: start; min-width: 0; }
.step { display: grid; gap: 6px; min-width: 0; }
.step > .lbl { font-size: 13px; font-weight: 700; display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.step > .lbl .n { font-family: var(--font-num); color: var(--accent); }
.step > .lbl .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  font: inherit; font-size: 14px; padding: 7px 16px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--line); }
.swatch.sw-0 { background: var(--sw-white); }
.swatch.sw-1 { background: var(--sw-silver); }
.swatch.sw-2 { background: var(--sw-black); }

.handle-opts { display: grid; gap: 8px; margin-top: 2px; }
.note { font-size: 13px; color: var(--muted); }
.unit-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.unit-row input { max-width: 140px; }
.unit { font-size: 13px; color: var(--muted); }

.widths .cells { display: grid; gap: 6px; }
.widths .cells label { display: grid; gap: 2px; font-size: 11px; color: var(--muted); text-align: center; min-width: 0; }
.widths .cells input { text-align: center; padding: 7px 4px; font-size: 17px; }
.widths .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.sum { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.sum.bad { color: var(--danger); font-weight: 700; }
.sum.good { color: var(--ok); }
.linkbtn { font: inherit; font-size: 12px; background: none; border: 1px solid var(--line); color: var(--accent); border-radius: 4px; padding: 3px 8px; cursor: pointer; }

.bars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.bars label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); min-width: 0; }
/* 바 수량 칸 안쪽 오른편 "개" — 길이가 아니라 개수임을 표시 */
.sfx { position: relative; display: block; }
.sfx input { padding-right: 30px; }
.sfx::after { content: '개'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); pointer-events: none; }

.drawing { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.drawing .canvas { border: 1px solid var(--line); border-radius: 6px; background: var(--paper); overflow-x: auto; }
.drawing svg, .done-set svg { display: block; width: 100%; height: auto; }
.drawing svg text, .done-set svg text { font-family: var(--font-num); }
.done-set svg text.cap { display: none; } /* 아래 설명에 같은 정보가 있고 작은 도면에선 치수와 겹침 */

.bom { border-top: 1px dashed var(--line); padding-top: 10px; font-size: 13px; display: grid; gap: 6px; }
.bom .t { font-weight: 700; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.bom ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.bom li { background: var(--accent-soft); border-radius: 4px; padding: 2px 8px; font-variant-numeric: tabular-nums; }
.drawing .memo { margin-top: auto; margin-bottom: 30px; } /* 열 맨 아래에서 30px 위로 */
.drawing .memo textarea { min-height: 72px; }

.err { color: var(--danger); font-size: 13px; }
.err:empty { display: none; }
.err ul { margin: 4px 0 0; padding-left: 18px; }
.add { font: inherit; padding: 12px; border: 1px dashed var(--accent); color: var(--accent); background: transparent; border-radius: 8px; cursor: pointer; font-weight: 700; }
.add:disabled { opacity: 0.45; cursor: not-allowed; }
.del { font: inherit; font-size: 13px; background: none; border: none; color: var(--danger); cursor: pointer; padding: 4px; }

.submit-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.submit-bar .summary { font-size: 14px; color: var(--muted); }
.submit { font: inherit; font-size: 16px; font-weight: 700; padding: 12px 32px; border: none; border-radius: 8px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.submit:disabled { opacity: 0.45; cursor: not-allowed; }
.submit-err { background: var(--danger-soft); border-radius: 6px; padding: 10px 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.contact-btn { font: inherit; font-size: 15px; font-weight: 700; padding: 12px 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); cursor: pointer; }
.print-btn { font: inherit; font-size: 15px; font-weight: 700; padding: 12px 20px; border: 1px solid var(--accent); border-radius: 8px; background: var(--paper); color: var(--accent); cursor: pointer; }
.print-note { font-size: 12px; color: var(--muted); }

/* 레일 최대 길이 초과 안내 */
.over { color: var(--danger); font-size: 13px; font-weight: 700; }
.over button { font: inherit; font-size: 12px; margin-left: 6px; padding: 2px 8px; border: 1px solid var(--danger); border-radius: 4px; background: var(--paper); color: var(--danger); cursor: pointer; }

/* 펠릭스 문의 팝업 */
dialog.contact { border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(360px, calc(100vw - 32px)); color: var(--ink); background: var(--paper); box-shadow: 0 12px 40px var(--shadow); }
dialog.contact::backdrop { background: var(--backdrop); }
dialog.contact h2 { margin: 0 0 14px; font-size: 19px; }
dialog.contact dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; }
dialog.contact dt { color: var(--muted); }
dialog.contact dd { margin: 0; font-variant-numeric: tabular-nums; }
dialog.contact dd a { color: var(--accent); font-weight: 700; text-decoration: none; }
dialog.contact .tbd { color: var(--muted); }
.qr { margin: 18px auto 0; width: 140px; height: 140px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; text-align: center; font-size: 12px; color: var(--muted); }
dialog.contact .close { margin-top: 18px; width: 100%; font: inherit; font-weight: 700; padding: 10px; border: none; border-radius: 8px; background: var(--accent); color: var(--on-accent); cursor: pointer; }

/* 전체 화면 안내 (로딩 / 잘못된 링크 / 네트워크 오류) */
.state { text-align: center; padding: 48px 20px; justify-items: center; }
.state p { margin: 0; }
.state .msg { font-size: 16px; font-weight: 700; }
.state .msg.danger { color: var(--danger); }
.state .detail { font-size: 14px; color: var(--muted); }

/* 접수 완료 */
.done-head { display: grid; gap: 6px; text-align: center; padding: 8px 0; }
.done-head h2 { margin: 0; font-size: 22px; color: var(--ok); }
.done-head .no { font-size: 15px; }
.done-head .no b { font-family: var(--font-num); font-size: 18px; }
.done-head .sub { font-size: 13px; color: var(--muted); }
.done-sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.done-set { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.done-set h3 { margin: 0; font-size: 14px; }
.done-set .desc { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.done-set .memo-line { font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; }
.done-actions { display: flex; justify-content: center; }

/* ── 주문 내역 팝업 ── */
.history-btn { padding: 8px 16px; font-size: 14px; }
dialog.history { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 32px); color: var(--ink); background: var(--paper); box-shadow: 0 12px 40px var(--shadow); }
dialog.history::backdrop { background: var(--backdrop); }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.history-head h2 { margin: 0; font-size: 19px; }
.history-note { margin: 4px 0 14px; font-size: 13px; color: var(--muted); }
.history-empty { margin: 24px 0; text-align: center; color: var(--muted); }
#historyBody { display: grid; gap: 10px; }
.h-order { border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.h-order > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 14px; cursor: pointer; font-size: 14px; }
.h-order[open] > summary { background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.h-date { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; }
.h-no { font-family: var(--font-num); color: var(--muted); }
.h-qty { color: var(--muted); }
.h-pill { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); white-space: nowrap; }
.h-pill--checked { color: var(--accent); border-color: var(--accent); }
.h-pill--converted { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.h-pill--canceled { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.h-body { padding: 12px 14px; display: grid; gap: 10px; }
.h-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.done-actions { gap: 8px; flex-wrap: wrap; }

/* ── 가입 직후 안내 (주문 페이지 상단) ── */
section.welcome { border-color: var(--ok); background: var(--ok-soft); gap: 10px; }
.welcome-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.welcome-head h2 { margin: 0; font-size: 17px; color: var(--ok); }
.welcome p { margin: 0; font-size: 14px; }
.welcome-link { display: flex; flex-wrap: wrap; gap: 8px; }
.welcome-link input { flex: 1 1 240px; min-width: 0; font-family: var(--font-num); }
.welcome-copied { font-size: 13px; color: var(--ok); }
.welcome-copied:empty { display: none; }

/* ── 거래처 등록 페이지 (/join/<code>) ── */
.join-wrap { max-width: 560px; }
.join-lead { margin: 0; font-size: 14px; }
.join-hint { font-size: 12px; }
.join-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.join-actions { justify-content: flex-end; }
.state .contact-btn { margin-top: 4px; }

@media (max-width: 420px) {
  section.panel { padding: 14px; }
  .set-body { padding: 12px; }
  .actions { width: 100%; }
  .actions > button { flex: 1 1 auto; }
  .submit { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ── 도면 출력 (A4 · 팩스) ── 화면에서는 숨기고, 인쇄 시 입력 화면 대신 이것만 출력.
   팩스는 흑백 1비트라 회색·배경색 없이 검정 선과 글자만 사용 */
#printSheet { display: none; }
@page { size: A4 portrait; margin: 12mm; }
@media print {
  :root { --draw: var(--print-ink); --dim: var(--print-ink); --muted: var(--print-ink); --danger: var(--print-ink); --ink: var(--print-ink); }
  body.ps-ready { background: var(--print-paper); margin: 0; font-size: 10.5pt; }
  body.ps-ready .wrap { display: none !important; }
  body.ps-ready #printSheet { display: block; color: var(--print-ink); }
  dialog.contact, dialog.history { display: none !important; }
}
.ps-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--print-ink); padding-bottom: 4px; }
.ps-head h1 { margin: 0; font-size: 18pt; letter-spacing: -0.02em; }
.ps-head .meta { font-size: 9.5pt; text-align: left; line-height: 1.4; }
.ps-notice { margin-top: 6px; border: 1.5px solid var(--print-ink); padding: 4px 8px; font-size: 10pt; font-weight: 700; }
.ps-fax { font-size: 13pt; font-weight: 800; }

.ps-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 10pt; }
.ps-table th, .ps-table td { border: 1px solid var(--print-ink); padding: 3px 6px; text-align: left; vertical-align: top; }
.ps-table th { width: 20mm; font-weight: 700; white-space: nowrap; }
.ps-set { border: 1.5px solid var(--print-ink); margin-top: 8px; break-inside: avoid; page-break-inside: avoid; }
.ps-set-head { border-bottom: 1px solid var(--print-ink); padding: 3px 8px; font-weight: 700; font-size: 11pt; display: flex; justify-content: space-between; }
.ps-set-body { display: grid; grid-template-columns: 78mm 1fr; }
.ps-set-body .ps-table { margin: 0; border: none; }
.ps-set-body .ps-table tr:first-child th, .ps-set-body .ps-table tr:first-child td { border-top: none; }
.ps-set-body .ps-table th:first-child { border-left: none; }
.ps-set-body .ps-table tr:last-child th, .ps-set-body .ps-table tr:last-child td { border-bottom: none; }
.ps-set-body .ps-table th { width: 22mm; }
.ps-draw { border-left: 1px solid var(--print-ink); padding: 4px; display: flex; align-items: center; }
.ps-draw svg { width: 100%; height: auto; max-height: 62mm; }
.ps-draw svg text { font-family: var(--font-num); font-size: 16px; font-weight: 700; } /* 팩스에서 읽히도록 치수 글자 확대 */
.ps-draw svg text.cap { display: none; } /* 표에 같은 정보가 있고 좁은 도면에선 치수와 겹침 */
.ps-memo { border-top: 1px solid var(--print-ink); padding: 3px 8px; font-size: 10pt; min-height: 9mm; white-space: pre-wrap; }
.ps-foot { margin-top: 10px; display: flex; justify-content: space-between; align-items: flex-end; font-size: 9.5pt; gap: 12px; break-inside: avoid; }
.ps-foot > div:first-child { flex: 1; min-width: 0; font-size: 9pt; }
.ps-foot-note { white-space: nowrap; font-size: 8.5pt; letter-spacing: -0.02em; } /* 한 줄 유지 */
.ps-sign { flex: none; border: 1px solid var(--print-ink); width: 44mm; height: 16mm; padding: 2px 6px; font-size: 9pt; }
