/* ============================================================
   style.css — sphotoeditor V2 룩 (theme.css 토큰 기반)
   엘리베이션은 그림자 대신 보더 강도. 그라디언트 금지.
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--surface-1);
  color: var(--text-1);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: var(--text-base); color: var(--text-1); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
svg.ico { width: 18px; height: 18px; stroke-width: 1.75; flex: 0 0 auto; }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.anim-rise { animation: rise var(--duration-base) var(--ease-out) both; }

/* ---------- 탑바 (56px 화이트 크롬) ---------- */
.topbar {
  height: 56px; flex: 0 0 auto;
  display: flex; align-items: center; gap: 20px; padding: 0 16px;
  background: var(--chrome-base);
  border-bottom: 1px solid var(--chrome-border);
}
.topbar .logo { display: flex; align-items: center; }
.topbar .logo img { height: 22px; display: block; }
.topbar nav { display: flex; gap: 2px; }
.topbar nav a {
  color: var(--text-2); text-decoration: none; font-size: var(--text-base); font-weight: 500;
  padding: 7px 12px; border-radius: var(--radius-sm); white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.topbar nav a:hover { background: var(--chrome-hover); color: var(--text-1); }
.topbar nav a.active { background: var(--brand-subtle); color: var(--brand); }
.topbar .spacer { flex: 1; }

/* ---------- 페이지 골격 ---------- */
.app { display: flex; height: calc(100dvh - 56px); overflow: hidden; }
.editor-shell { display: flex; flex-direction: column; height: 100dvh; }
.editor-main { display: flex; flex: 1; min-height: 0; }

/* ---------- 아이콘 레일 (72px) ---------- */
.rail {
  width: 72px; flex: 0 0 auto;
  background: var(--chrome-base); border-right: 1px solid var(--chrome-border);
  display: flex; flex-direction: column; align-items: stretch; padding: 8px 0; gap: 2px;
  overflow-y: auto;
}
.rail button {
  position: relative; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0 8px; color: var(--text-2);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.rail button svg { width: 24px; height: 24px; stroke-width: 1.75; }
.rail button .lbl { font-size: 11px; font-weight: 500; line-height: 1; }
.rail button:hover { background: var(--chrome-hover); color: var(--text-1); }
.rail button.on { color: var(--brand); }
.rail button.on::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: var(--radius-full); background: var(--brand);
}

/* ---------- 사이드바 (모든 도구가 한 축에 보이는 단일 스크롤) ---------- */
.sidebar {
  width: 360px; flex: 0 0 auto;
  background: var(--chrome-panel); border-right: 1px solid var(--chrome-border);
  overflow-y: auto; min-height: 0;
}
.side-group {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-bottom: 1px solid var(--border-1);
}
.side-group[hidden] { display: none; }
.side-group > h4 {
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em;
  color: var(--text-3); text-transform: uppercase;
  display: flex; align-items: center; gap: 8px;
}
.side-group h3 {
  font-size: var(--text-sm); font-weight: 600; color: var(--text-1);
  display: flex; justify-content: space-between; align-items: center;
}
.side-group h3 .val { color: var(--brand); font-weight: 600; font-variant-numeric: tabular-nums; }
/* 물음표 도움말 (호버 툴팁) */
.help {
  position: relative; width: 26px; height: 26px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-2); border-radius: var(--radius-full);
  color: var(--text-3); font-size: 12px; font-weight: 700; cursor: help;
}
.help:hover, .help:focus { color: var(--brand); border-color: var(--brand); outline: none; }
.help .tip {
  display: none; position: absolute; z-index: 30;
  top: calc(100% + 8px); right: -4px; width: 250px;
  background: var(--neutral-900); color: var(--text-inverse);
  padding: 10px 12px; border-radius: var(--radius-md);
  font-size: var(--text-xs); font-weight: 400; line-height: 1.55; cursor: default;
}
.help .tip b { color: var(--brand-cta); }
.help:hover .tip, .help:focus .tip { display: block; }

.admin-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0;
  background: var(--brand-subtle); color: var(--brand);
  padding: 2px 7px; border-radius: var(--radius-full); text-transform: none;
}

/* ---------- 슬라이드 패널 (350px) ---------- */
.panel {
  width: 350px; flex: 0 0 auto;
  background: var(--chrome-panel); border-right: 1px solid var(--chrome-border);
  display: flex; flex-direction: column; min-height: 0;
}
.panel.hidden { display: none; }
.panel-head {
  height: 48px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; border-bottom: 1px solid var(--chrome-border);
}
.panel-head h2 { font-size: var(--text-md); font-weight: 600; letter-spacing: var(--tracking-snug); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.panel-body .section[hidden] { display: none; }

.iconbtn {
  width: 32px; height: 32px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.iconbtn:hover { background: var(--chrome-hover); color: var(--text-1); }

/* ---------- 섹션 / 라벨 / 힌트 ---------- */
.section { display: flex; flex-direction: column; gap: 8px; }
.section h3 {
  font-size: var(--text-sm); font-weight: 600; color: var(--text-1);
  display: flex; justify-content: space-between; align-items: center;
}
.section h3 .val { color: var(--brand); font-weight: 600; font-variant-numeric: tabular-nums; }
.hint { font-size: var(--text-xs); color: var(--text-2); line-height: 1.5; }
.hint b { color: var(--text-1); font-weight: 600; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--border-2); background: transparent; color: var(--text-1);
  border-radius: var(--radius-sm); font-size: var(--text-base); font-weight: 500;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn.primary, .btn.accent {
  background: var(--brand-cta); border-color: var(--brand-cta); color: var(--brand-cta-text);
  font-weight: 600;
}
.btn.primary:hover, .btn.accent:hover { background: var(--brand-cta-hover); border-color: var(--brand-cta-hover); }
.btn.small { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.toggled { background: var(--brand-subtle); border-color: var(--brand); color: var(--brand); }

.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.row .fixed { flex: 0 0 auto; }

/* ---------- 입력 ---------- */
input[type=number], input[type=text], input[type=password], select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-0); outline: none;
  transition: border-color var(--duration-fast) var(--ease-out);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-color: var(--border-2); }
/* 크기 기준 축: 노란 칸 = 고정 기준(사용자 입력), read-only 칸 = 형상 따라 자동 변동 */
input.locked { background: #FFF6C2; border-color: var(--brand); }
input.locked:focus { border-color: var(--brand); }
#inpW[readonly], #inpH[readonly] { background: var(--surface-2); color: var(--text-3); }
input[type=range] { width: 100%; height: auto; accent-color: var(--brand); padding: 0; border: 0; }
input[type=range]:focus { outline: none; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235C5C5C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 32px;
}

/* ---------- 세그먼트 ---------- */
.seg {
  display: flex; gap: 2px; padding: 2px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--text-2);
  height: 32px; padding: 0 8px; border-radius: var(--radius-xs);
  font-size: var(--text-sm); font-weight: 500;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.seg button:hover { color: var(--text-1); }
.seg button.on { background: var(--surface-0); color: var(--text-1); font-weight: 600; box-shadow: var(--shadow-xs); }

/* ---------- 캔버스 스테이지 ---------- */
.stage { flex: 1; position: relative; display: flex; flex-direction: column; overflow: hidden; background: var(--chrome-canvas); }
.stage canvas { flex: 1; width: 100%; height: 100%; display: block; }
.stage .overlay-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--neutral-900); color: var(--text-inverse);
  padding: 8px 16px; border-radius: var(--radius-full);
  font-size: var(--text-sm); pointer-events: none; opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-out); white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.stage .overlay-hint.show { opacity: 1; }
.stage-actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.stage-actions .btn, .stage-actions select { background: var(--chrome-elevated); box-shadow: var(--shadow-xs); }
.stage-actions .btn.accent { background: var(--brand-cta); }
.stage-actions select { width: auto; }

/* 부유형(채팅 페이지) 메트릭 — 우측 줌 컨트롤과 겹치지 않게 좌측 정렬 */
.metricsbar {
  position: absolute; bottom: 14px; left: 14px;
  display: flex; gap: 18px; align-items: center;
  background: var(--chrome-elevated); border: 1px solid var(--chrome-border);
  padding: 9px 18px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  font-size: var(--text-sm); color: var(--text-2); white-space: nowrap;
}
.metricsbar b { color: var(--text-1); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 하단 바 (44px, 에디터) ---------- */
.bottombar {
  height: 44px; flex: 0 0 auto;
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: var(--chrome-base); border-top: 1px solid var(--chrome-border);
  font-size: var(--text-sm); color: var(--text-2);
}
.bottombar .metricsbar {
  position: static; transform: none; border: 0; box-shadow: none; padding: 0;
  background: transparent; border-radius: 0;
}
.bottombar .spacer { flex: 1; }
.zoomctl { display: flex; align-items: center; gap: 6px; }
.zoomctl input[type=range] { width: 120px; }
/* 부유형 줌 컨트롤 (채팅 미리보기 우하단) */
.stage-zoom {
  position: absolute; right: 14px; bottom: 14px;
  background: var(--chrome-elevated); border: 1px solid var(--chrome-border);
  padding: 7px 12px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.stage-zoom input[type=range] { width: 90px; }
.zoomctl .zoomval {
  min-width: 44px; text-align: right;
  font-size: var(--text-sm); font-weight: 600; color: var(--text-1); font-variant-numeric: tabular-nums;
}

/* ---------- 채팅 ---------- */
.chat-panel {
  width: 420px; min-width: 380px; flex: 0 0 auto;
  display: flex; flex-direction: column;
  background: var(--chrome-panel); border-right: 1px solid var(--chrome-border);
}
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg {
  max-width: 88%; padding: 10px 14px; border-radius: var(--radius-lg);
  line-height: 1.6; white-space: pre-wrap; word-break: break-word; font-size: var(--text-base);
  animation: rise var(--duration-base) var(--ease-out) both;
}
.msg.user { align-self: flex-end; background: var(--neutral-900); color: var(--text-inverse); border-bottom-right-radius: var(--radius-xs); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: var(--radius-xs); }
.msg.system {
  align-self: center; background: var(--brand-subtle); color: var(--brand);
  font-size: var(--text-xs); font-weight: 500; padding: 5px 12px; border-radius: var(--radius-full);
}
.msg img.att { max-width: 200px; border-radius: var(--radius-sm); display: block; margin-top: 6px; }
.msg .file-chip {
  display: inline-flex; gap: 6px; align-items: center;
  background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: var(--radius-xs);
  font-size: var(--text-xs); margin-top: 6px;
}
.msg.assistant .file-chip { background: var(--surface-3); }
.chat-input { border-top: 1px solid var(--chrome-border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-attach-preview { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-attach-preview .chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); padding: 4px 8px; border-radius: var(--radius-xs); font-size: var(--text-xs);
}
.chat-attach-preview .chip button { border: 0; background: none; color: var(--text-2); font-size: var(--text-base); }
.chat-input .inputrow { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-0); padding: 9px 12px; max-height: 120px; outline: none; line-height: 1.5;
}
.chat-input .iconbtn {
  width: 40px; height: 40px; border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-0); color: var(--text-2);
}
.chat-input .iconbtn:hover { background: var(--surface-2); color: var(--text-1); }
.chat-input .iconbtn.send { background: var(--brand-cta); border-color: var(--brand-cta); color: var(--brand-cta-text); }
.chat-input .iconbtn.send:hover { background: var(--brand-cta-hover); border-color: var(--brand-cta-hover); }
.typing { display: flex; gap: 4px; padding: 12px 16px; align-self: flex-start; }
.typing i { width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--text-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.3} 40%{opacity:1} }

/* ---------- 견적 박스 ---------- */
/* ---------- 고리 카드 (고리별 개별 설정) ---------- */
.hole-card {
  background: var(--surface-1); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.hole-card .hole-head { display: flex; align-items: center; gap: 8px; }
.hole-card .hole-head b { font-size: var(--text-sm); color: var(--text-1); }
.hole-card .hole-head .outer { font-size: var(--text-xs); color: var(--text-2); flex: 1; }
.hole-card .hole-head .del {
  width: 24px; height: 24px; border: 0; background: transparent; color: var(--text-3);
  border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.hole-card .hole-head .del:hover { background: var(--surface-2); color: var(--danger); }
.hole-card .hole-head .del svg { width: 14px; height: 14px; stroke-width: 2; }
.hole-card input[type=number] { height: 34px; }
.hole-card .seg button { height: 30px; }

.quote-box {
  background: var(--surface-1); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); padding: 12px 14px; font-size: var(--text-sm); color: var(--text-2);
}
.quote-box table { width: 100%; border-collapse: collapse; }
.quote-box td { padding: 4px 0; }
.quote-box td:last-child { text-align: right; font-weight: 600; color: var(--text-1); font-variant-numeric: tabular-nums; }
.quote-box tr.total td {
  border-top: 1px solid var(--border-1); padding-top: 8px;
  font-size: var(--text-md); font-weight: 700; color: var(--brand);
}

/* ---------- 어드민 / 문서형 페이지 ---------- */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 28px 20px 90px; }
.admin-wrap h2 {
  margin: 28px 0 12px; font-size: var(--text-lg); font-weight: 600; letter-spacing: var(--tracking-snug);
}
.card {
  background: var(--surface-0); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); padding: 16px;
  transition: border-color var(--duration-fast) var(--ease-out);
}
table.grid { width: 100%; border-collapse: collapse; background: var(--surface-0); }
table.grid th, table.grid td { border-bottom: 1px solid var(--border-1); padding: 9px 12px; font-size: var(--text-sm); text-align: left; }
table.grid th { background: var(--surface-1); font-weight: 600; color: var(--text-2); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid input { height: 32px; border: 1px solid transparent; background: transparent; width: 100%; padding: 0 8px; border-radius: var(--radius-xs); }
table.grid input:focus { border-color: var(--border-2); background: var(--surface-0); outline: 2px solid var(--focus-ring); outline-offset: 0; }
.savebar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--chrome-base); border-top: 1px solid var(--chrome-border);
  padding: 12px 24px; display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; top: 70px; right: 20px; z-index: 99;
  background: var(--neutral-900); color: var(--text-inverse);
  padding: 10px 16px; border-radius: var(--radius-md); font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0; transition: opacity var(--duration-slow) var(--ease-out); pointer-events: none;
}
.toast.show { opacity: 1; }

.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 20px; }

/* ---------- 주문 카드 (상담 대화 내 결제) ---------- */
.order-card { display: flex; flex-direction: column; gap: 8px; min-width: 260px; }
.order-card .oc-title { font-weight: 700; font-size: var(--text-md); }
.order-card .oc-note { color: var(--text-2); }
.order-card .oc-line b { color: var(--brand-cta-text, inherit); }
.order-card .oc-row { display: flex; align-items: center; gap: 8px; }
.order-card .oc-row label { flex: 0 0 auto; color: var(--text-2); font-size: var(--text-sm); }
.order-card .oc-qty { width: 76px; height: 34px; }
.order-card .oc-total { margin-left: auto; font-variant-numeric: tabular-nums; }
.order-card input[type=text], .order-card input[type=tel] { height: 36px; }
.order-card .oc-hint { font-size: var(--text-xs, 12px); color: var(--text-3); }
.order-card .oc-pay { width: 100%; }

/* ---------- 모바일 (≤768px): 세로 배치 — 미리보기가 항상 위에 보이게 ---------- */
@media (max-width: 768px) {
  /* 상담: 위 = 미리보기(44%), 아래 = 채팅 */
  .app { flex-direction: column; }
  .app .stage { order: -1; flex: 0 0 44dvh; min-height: 260px; }
  .chat-panel {
    width: 100%; min-width: 0; flex: 1; min-height: 0;
    border-right: 0; border-top: 1px solid var(--chrome-border);
  }

  /* 에디터: 위 = 캔버스(48%), 아래 = 도구 사이드바 스크롤 (하단바는 editor-main 밖 형제라 그대로 맨 아래) */
  .editor-main { flex-direction: column; }
  .editor-main .stage { order: -1; flex: 0 0 48dvh; min-height: 260px; }
  .sidebar {
    width: 100%; flex: 1; min-height: 0;
    border-right: 0; border-top: 1px solid var(--chrome-border);
  }

  /* 미리보기 위 액션(재료/배경제거/다운로드): 좁은 폭에서 줄바꿈 허용 */
  .stage-actions {
    left: 14px; right: 14px; flex-wrap: wrap; justify-content: flex-end;
  }

  /* 부유 메트릭/줌: 작게 — 캔버스 가림 최소화 */
  .metricsbar { gap: 10px; padding: 6px 10px; font-size: var(--text-xs, 12px); bottom: 10px; left: 10px; }
  .stage-zoom { right: 10px; bottom: 10px; padding: 5px 8px; }
  .stage-zoom input[type=range] { display: none; } /* 모바일은 −/+/맞춤 버튼으로 충분 */
  .bottombar { height: auto; min-height: 40px; flex-wrap: wrap; padding: 4px 12px; gap: 10px; }
  .zoomctl input[type=range] { width: 80px; }

  /* 표(견적 비교/재료 단가): 가로 스크롤 허용 */
  .card { overflow-x: auto; }
  table.grid { min-width: 520px; }
}
