/* Brass Portal — single stylesheet, mobile first (min width 360px). */

:root {
  --brass: #b5a642;
  --brass-dark: #8a7a2a;
  --ink: #1f1d1a;
  --muted: #6b6760;
  --bg: #faf8f3;
  --card: #ffffff;
  --line: #e6e1d6;
  --danger: #c0392b;
  --radius: 12px;
  --gap: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-width: 360px;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  line-height: 1.6;
  word-break: keep-all;
}

.site-header {
  padding: 12px var(--gap);
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.brand { display: inline-flex; align-items: center; font-weight: 700; color: var(--brass-dark); text-decoration: none; }
.brand img { display: block; height: 44px; width: auto; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--gap);
}

.site-footer {
  padding: 24px var(--gap);
  text-align: center;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px var(--gap);
  margin-bottom: var(--gap);
}

h1 { font-size: 1.375rem; margin: 0 0 8px; }

.muted { color: var(--muted); font-size: 0.875rem; }

/* One primary action per screen (SPEC 6절). */
.btn-primary {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--brass);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error { color: var(--danger); }

h2 { font-size: 1.125rem; margin: 0 0 12px; }

.center { text-align: center; }

/* Forms */
.form { display: grid; gap: var(--gap); margin-top: var(--gap); }

.field { display: grid; gap: 6px; font-weight: 600; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1.125rem;
  background: #fff;
}

.input:focus { outline: 2px solid var(--brass); border-color: var(--brass); }

.input-key { letter-spacing: 0.15em; text-transform: uppercase; }

.field-error { color: var(--danger); font-size: 0.875rem; font-weight: 400; }

.alert {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #fdecea;
  color: var(--danger);
}

.btn-link {
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.875rem;
  cursor: pointer;
}

/* Dashboard */
.credits { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.credits strong { font-size: 1.75rem; color: var(--brass-dark); }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.step { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.step .dot {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
}

.step-done { color: var(--ink); }
.step-done .dot { background: var(--brass); border-color: var(--brass); }
.step-current { color: var(--ink); font-weight: 700; }
.step-current .dot { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(181, 166, 66, 0.25); }

.badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brass);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Photo upload */
.back { color: var(--muted); text-decoration: none; font-size: 0.875rem; }

.notice {
  padding: 12px;
  border-radius: 8px;
  background: #eef6e8;
  color: #2f6b1f;
}

.alert p { margin: 0; }
.alert p + p { margin-top: 4px; }

.guide { margin: 8px 0 16px; padding-left: 20px; display: grid; gap: 4px; }

.photo-preview {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  background: #f1eee6;
}

.btn-secondary {
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}

/* Consent popup */
.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 20px var(--gap);
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.dialog::backdrop { background: rgba(31, 29, 26, 0.55); }

.check { display: flex; gap: 10px; align-items: flex-start; line-height: 1.5; }

.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--brass); }

.dialog-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

/* Customer portal: left step navigation + content (stacks on mobile) */
.page-wide { max-width: 1040px; }

.portal { display: grid; gap: var(--gap); }

.portal-nav {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.nav-summary {
  display: grid;
  gap: 2px;
  padding: 8px 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.nav-option { font-weight: 700; font-size: 0.9375rem; }
.nav-credits { color: var(--muted); font-size: 0.8125rem; }
.nav-credits strong { color: var(--brass-dark); }

.steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }

.step-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.step-link:hover { background: #f4f1e8; }
.step-link.is-selected { background: #f1ecd8; box-shadow: inset 3px 0 0 var(--brass); }

.step-no {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  background: #fff;
}

.step-done .step-no { background: var(--brass); border-color: var(--brass); color: #fff; }
.step-current { font-weight: 700; }
.step-current .step-no { border-color: var(--brass); color: var(--brass-dark); box-shadow: 0 0 0 3px rgba(181, 166, 66, 0.25); }
.step-locked { color: var(--muted); }
.step-lock { margin-left: auto; font-size: 0.75rem; opacity: 0.7; }
.step-link .badge { margin-left: auto; }

.nav-logout { margin-top: 8px; padding: 8px; border-top: 1px solid var(--line); }

.step-eyebrow { margin: 0 0 4px; color: var(--brass-dark); font-size: 0.8125rem; font-weight: 700; }

.locked { border-color: #e7d9a8; background: #fffaf0; }
.locked .btn-primary { margin-top: 12px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Mobile: steps become a horizontal strip above the content. */
@media (max-width: 767px) {
  .portal-nav { padding: 8px; }
  .nav-summary { padding: 4px 4px 8px; }
  .steps { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
  .steps li { flex: none; }
  .step-link { min-height: 40px; padding: 6px 10px; white-space: nowrap; }
  .step-link.is-selected { box-shadow: inset 0 -3px 0 var(--brass); }
  .step-link .badge, .step-lock { margin-left: 4px; }
  .nav-logout { display: none; }
}

@media (min-width: 768px) {
  .portal { grid-template-columns: 260px 1fr; align-items: start; }
  .portal-nav { position: sticky; top: var(--gap); }
}

/* 2D concepts */
.concept-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.concept { margin: 0; border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.concept.is-selected { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(181, 166, 66, 0.25); }

.concept-image { position: relative; aspect-ratio: 1 / 1; background: #f1eee6; }
.concept-image img { display: block; width: 100%; height: 100%; object-fit: cover; }

.zoom-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.zoom-btn:hover { background: #fff; color: var(--brass-dark); }

.concept-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--brass);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.concept figcaption { display: grid; gap: 8px; padding: 10px; }
.concept-label { font-weight: 700; }
.concept-desc { color: var(--muted); font-size: 0.8125rem; margin-top: -6px; }

.btn-small {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--brass);
  border-radius: 8px;
  background: #fff;
  color: var(--brass-dark);
  font-weight: 700;
  cursor: pointer;
}

.btn-small:hover { background: var(--brass); color: #fff; }
.btn-secondary.wide { width: 100%; }

.progress { display: flex; gap: 16px; align-items: center; }

.spinner {
  width: 36px;
  height: 36px;
  flex: none;
  border: 4px solid #eee6c8;
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Zoom popup */
.zoom-dialog { width: min(900px, calc(100vw - 24px)); padding: 12px; }
.zoom-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.zoom-close { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #f1eee6; font-size: 1.1rem; cursor: pointer; }
.zoom-dialog img { display: block; width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: 8px; background: #f1eee6; }

@media (max-width: 420px) {
  .concept-grid { gap: 8px; }
  .concept figcaption { padding: 8px; }
}

/* AI edit chat (step 3) */
.chat { display: grid; gap: 12px; padding-bottom: 12px; }

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.btn-confirm {
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--brass);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn-confirm:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-log {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  display: grid;
  gap: 14px;
  max-height: min(70vh, 900px);
  overflow-y: auto;
}

.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; line-height: 1.55; }
.bubble p { margin: 0; }
.bubble-name { display: block; margin-bottom: 4px; font-size: 0.75rem; font-weight: 700; color: var(--brass-dark); }

.bubble-ai { justify-self: start; background: #f4f1e8; border-top-left-radius: 4px; }
.bubble-me { justify-self: end; background: var(--brass); color: #fff; border-top-right-radius: 4px; }
.bubble-me p { white-space: pre-wrap; }
.bubble-failed { background: #fdecea; color: var(--danger); }

.chat-image { position: relative; margin-top: 10px; width: min(360px, 100%); aspect-ratio: 1 / 1; border-radius: 12px; overflow: hidden; background: #e9e4d6; }
.chat-image img { display: block; width: 100%; height: 100%; object-fit: cover; }

.typing { display: inline-flex; gap: 3px; vertical-align: middle; margin-right: 6px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--brass-dark); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.chat-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chat-composer textarea {
  width: 100%;
  min-height: 52px;
  max-height: 160px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  resize: vertical;
}

.chat-composer textarea:focus { outline: 2px solid var(--brass); border-color: var(--brass); }

.btn-send {
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--brass);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-empty { grid-template-columns: 1fr; }

@media (max-width: 420px) {
  .bubble { max-width: 96%; }
  .chat-toolbar { flex-wrap: wrap; }
}

/* 3D viewer (step 4) */
.viewer { position: relative; border-radius: var(--radius); overflow: hidden; background: radial-gradient(ellipse at 50% 35%, #fbfbfa 0%, #ecebe8 65%, #dedcd7 100%); touch-action: none; }
.viewer canvas { display: block; width: 100%; }

.viewer-hud {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.viewer-hud span {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.8125rem;
  font-weight: 700;
}

.viewer-reset {
  pointer-events: auto;
  min-height: 36px;
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 0.8125rem;
  cursor: pointer;
}

.viewer-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.viewer-loading[hidden] { display: none; }

.machinability { margin-top: 12px; }
.machining-rule { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: #f7f3e6; font-size: 0.8125rem; line-height: 1.6; }

.versions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.version-btn {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.version-btn.is-active { border-color: var(--brass); box-shadow: inset 3px 0 0 var(--brass); background: #fbf8ef; }
.version-btn span:nth-of-type(1) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-warn { color: var(--danger); font-size: 0.75rem; font-weight: 700; }

/* 지난 기록(사진·시안·대화) */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.history-item { margin: 0; text-align: center; }
.history-item figcaption { font-size: 0.8rem; margin-top: 4px; }
.history-item.is-selected .history-thumb { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(181, 166, 66, 0.25); }
.history-thumb { display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; background: #f1eee6; cursor: zoom-in; }
.history-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.history-round { font-size: 0.95rem; margin: 16px 0 8px; }
.source-photo { display: flex; gap: 14px; align-items: center; }
.source-photo .history-thumb { width: 88px; flex: none; }
.source-photo h2 { margin: 0 0 4px; font-size: 1rem; }
.history-chat { border-top: 1px solid var(--line); padding: 10px 0; }
.history-chat summary { cursor: pointer; font-weight: 600; }
.bubble-time { display: block; font-size: 0.75rem; opacity: 0.7; margin-top: 2px; text-align: right; }

/* 메꿈 부위 겹쳐 보기 */
.fill-toggle { margin: 8px 0; }
.fill-mark { color: #d0342c; }

/* 3D 제공자 패널 나란히 보기 */
.viewer-panels { display: grid; gap: 16px; }
@media (min-width: 900px) { .viewer-panels.is-multi { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.viewer-panel { min-width: 0; }
.viewer-title { margin: 0 0 8px; font-size: 1.05rem; }
.fill-toggle[hidden] { display: none; }
.version-picked { color: var(--brass); font-weight: 600; font-size: 0.8rem; }

/* 3D 크게 보기: 패널의 돋보기 버튼과 팝업 */
.viewer .viewer-zoom { position: absolute; top: 10px; right: 10px; z-index: 2; }
.viewer-dialog { width: min(1100px, 96vw); max-width: 96vw; max-height: 96vh; padding: 12px; }
.viewer-dialog .viewer { position: relative; border-radius: 8px; overflow: hidden; }
.viewer-dialog-foot { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-top: 8px; }
.viewer-dialog-foot .muted { margin: 0; }

/* 가공 형상 패널: AI 3D 아래에 구분선과 함께 */
.viewer-panel[data-testid="viewer-machined"] { border-top: 1px solid var(--line); padding-top: 16px; }
