/* ============================================================
   KS JARVIS VISION — 스타일 (KSTYLE 브랜드 v3)
   모노크롬 흑백 베이스 + 기능 액센트 2종(재고=그린 도트 / 경고=앰버)
   세로 스트라이프·산(山) 모티프 · 풀스크린 카메라 · AR 재고 배지
   클래스/ID는 index.html + overlay.js(renderBadge)와 1:1 대응.
   ※ 시각 전용 리스타일 — JS가 쓰는 id/class 계약은 변경하지 않음.
   ============================================================ */

:root {
  --bg: #0b0b0d;             /* index.html theme-color와 동일 (KSTYLE 니어블랙) */
  --bg-deep: #0b0b0d;
  --ink: #ffffff;
  --card: rgba(10, 10, 13, 0.82);
  --card-border: rgba(255, 255, 255, 0.16);
  --text: #f4f4f5;
  --text-dim: #9b9ba1;
  --accent: #34d399;         /* 기능 액센트 1: 재고 인디케이터(그린 도트) */
  --warn: #f5c042;           /* 기능 액센트 2: 경고/모의 데이터(앰버) */
  --error: #f5c042;          /* 오류도 앰버 계열로 통일 (모노크롬 유지) */
  --fade-ms: 250ms;          /* overlay.js FADE_MS와 동일해야 함 */
  --font-brand: "Montserrat", "Pretendard", -apple-system, BlinkMacSystemFont,
                "Helvetica Neue", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
               "Noto Sans KR", "Malgun Gothic", sans-serif;
  /* 모바일: 텍스트 선택/탭 하이라이트/더블탭 줌 차단 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ---------- 풀스크린 카메라 ---------- */

#camera {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;   /* app.js makeMapper()의 cover 좌표 매핑과 짝 */
  background: #000;
  z-index: 0;
  /* 디지털 줌: camera.js가 scale(z) 적용 — 중앙 기준 확대.
     makeMapper는 getBoundingClientRect(transform 반영)라 좌표 매핑 그대로 정합. */
  transform-origin: 50% 50%;
  will-change: transform;
}

/* ---------- 카메라 브랜드 크롬 (시각 전용 — 비디오 위 / 배지 아래) ---------- */

#cam-chrome {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

#cam-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 14px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.35) 60%, transparent 100%);
}

.ch-wordmark {
  font-family: var(--font-brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink);
  white-space: nowrap;
}

.ch-wordmark span {
  font-weight: 300;
  color: rgba(255, 255, 255, 0.78);
}

/* 매장 라벨 자리 (제주/부산 — 추후 채움, 지금은 "—") */
#store-badge {
  min-width: 36px;
  padding: 4px 12px;
  text-align: center;
  font-family: var(--font-brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #0b0b0d;
  background: var(--ink);          /* KS INTERNATIONAL 반전 pill 모티프 */
  border-radius: 999px;
}

/* 스캔 가이드 프레임 — 4코너 브래킷 */
#scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* vmin: 가로 모드에서도 짧은 변 기준 → 프레임이 화면 위아래로 잘리지 않음
     (세로 모드에서는 vmin == vw 라 기존과 동일) */
  width: min(64vmin, 280px);
  aspect-ratio: 1 / 1;
  opacity: 0.9;
}

.sf-corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2.5px solid var(--ink);
}

.sf-tl { top: 0;    left: 0;  border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.sf-tr { top: 0;    right: 0; border-left: none;  border-bottom: none; border-top-right-radius: 8px; }
.sf-bl { bottom: 0; left: 0;  border-right: none; border-top: none;    border-bottom-left-radius: 8px; }
.sf-br { bottom: 0; right: 0; border-left: none;  border-top: none;    border-bottom-right-radius: 8px; }

/* 하단 안내줄 */
#scan-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* ---------- 재고 배지 레이어 ---------- */

#overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

/* 배지: overlay.js가 transform: translate(-50%,-100%) translate(x,y)로
   직접 이동시키므로 기준점은 반드시 left:0 / top:0 */
.badge {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform, opacity;
  max-width: 78vw;
  padding: 9px 16px 10px;
  background: var(--card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--fade-ms) ease-out;
}

.badge.fading { opacity: 0; }

/* 배지 상태별 톤 (overlay.js dataset.state) — 경고/오류 = 앰버 */
.badge[data-state="notfound"] { border-color: rgba(245, 192, 66, 0.5); }
.badge[data-state="error"]    { border-color: rgba(245, 192, 66, 0.55); }

/* 배지 내부 */
.b-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 5px;
  max-width: 74vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.b-variants {
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim);
  margin-bottom: 4px;
  white-space: normal;
  max-width: 70vw;
}

.b-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* 재고 수치 — 모노크롬 화이트 + 그린 도트(유일한 재고 액센트) */
.b-stock {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.b-jeju, .b-busan { color: var(--ink); }

.b-jeju::before,
.b-busan::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 3px;
}

.b-loading {
  font-size: 13px;
  color: var(--text-dim);
  gap: 8px;
}

.b-warn  { font-size: 14px; font-weight: 600; color: var(--warn); }
.b-error { font-size: 14px; font-weight: 600; color: var(--error); }

/* ⓘ 정보 버튼 — 제품 상세 바텀시트 열기.
   배지 레이어(#overlay)는 pointer-events:none — 이 버튼만 auto로 탭 가능 */
.b-info {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  display: inline-block;
  margin-top: 7px;
  padding: 5px 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.b-info:active { background: rgba(255, 255, 255, 0.22); }

/* ---------- 모의 데이터 (mock) — 가짜 숫자 실재고 오인 방지 ---------- */

/* mock 배지: 수치는 "—"로 대체되고 흐리게 (overlay.js stockRowHtml) */
.badge.mock { border-color: rgba(245, 192, 66, 0.6); }
.b-mock .b-jeju,
.b-mock .b-busan { opacity: 0.5; }
.b-mock .b-jeju::before,
.b-mock .b-busan::before { background: var(--text-dim); }

/* 🧪 DEMO 태그 — 앰버 솔리드, 실재고와 절대 혼동 불가 */
.b-demo {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #0b0b0d;
  background: var(--warn);
  padding: 3px 9px;
  border-radius: 6px;
  text-shadow: none;
}

/* 모의 데이터 상시 경고 배너 (index.html #mock-banner, app.js setMockBanner) */
#mock-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;               /* 배지(10)·상태(15)·화면(20)보다 위 — 항상 보임 */
  pointer-events: none;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--warn);
  background: rgba(11, 11, 13, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--warn);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

#mock-banner.hidden { display: none; }

/* 배너가 떠 있으면 상태 안내 pill을 배너+헤더 아래로 내림 */
#mock-banner:not(.hidden) ~ #status {
  top: calc(env(safe-area-inset-top, 0px) + 100px);
}

/* ---------- 카메라 줌 컨트롤 (창고 천장 QR — KSTYLE 모노크롬 pill) ---------- */

#zoom-ctl {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  /* 스캔 안내줄(bottom 30px) 위 — 스캔 프레임(중앙)·배지와 안 겹침 */
  bottom: calc(env(safe-area-inset-bottom, 0px) + 62px);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}

#zoom-ctl.hidden { display: none; }

#zoom-ctl button {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#zoom-ctl button:active { background: rgba(255, 255, 255, 0.26); }

#zoom-val {
  min-width: 48px;
  text-align: center;
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* 가로 모드: 안내줄이 올라가므로 줌 컨트롤도 같이 (스캔 프레임 회피) */
@media (orientation: landscape) {
  #zoom-ctl { bottom: calc(env(safe-area-inset-bottom, 0px) + 44px); }
}

/* ---------- 제품 상세 바텀시트 (배지 ⓘ 정보) ---------- */

#detail-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;            /* mock 배너(30)보다 위 — 열려 있는 동안 최상위 */
}

#detail-sheet.hidden { display: none; }

#ds-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

#ds-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: rgba(13, 13, 16, 0.97);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  animation: ds-up 0.22s ease-out;
}

@keyframes ds-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#ds-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#ds-title {
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink);
}

#ds-close {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#ds-close:active { background: rgba(255, 255, 255, 0.16); }

#ds-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 20px 8px;
}

.ds-item + .ds-item {
  margin-top: 12px;
  border-top: 1px dashed rgba(255, 255, 255, 0.18);
  padding-top: 12px;
}

.ds-table {
  width: 100%;
  border-collapse: collapse;
}

.ds-table tr + tr { border-top: 1px solid rgba(255, 255, 255, 0.07); }

.ds-table th {
  width: 38%;
  padding: 11px 12px 11px 0;
  text-align: left;
  vertical-align: top;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  white-space: nowrap;
}

.ds-table td {
  padding: 11px 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

/* ---------- 판매단가 섹션 (바텀시트 내) — KSTYLE 모노크롬 ---------- */

.ds-price-sec {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  padding-top: 10px;
}

.ds-sec-label {
  font-family: var(--font-brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.ds-price-table th { width: 30%; }

.ds-price-num {
  display: inline-block;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.ds-vat-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  vertical-align: 2px;
  white-space: nowrap;
}

.ds-vat-incl {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.ds-price-none {
  color: var(--text-dim) !important;
  font-weight: 500 !important;
}

.ds-price-note {
  padding: 10px 0 4px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.ds-loading, .ds-empty {
  padding: 28px 0 22px;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
}

/* 로딩 스피너 */
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---------- 상단 상태 안내 (브랜드 헤더 아래) ---------- */

#status {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  pointer-events: none;
  max-width: 86vw;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status:not(:empty) {
  padding: 7px 16px;
  background: var(--card);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ---------- 시작/오류 풀스크린 화면 (KSTYLE 모노크롬) ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    /* 미세 세로 스트라이프 텍스처 (기둥/바코드 모티프, 아주 은은하게) */
    repeating-linear-gradient(90deg,
      rgba(255, 255, 255, 0.025) 0 1px,
      transparent 1px 16px),
    var(--bg-deep);
  padding: calc(env(safe-area-inset-top, 0px) + 24px)
           28px
           calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.screen.hidden { display: none; }

.screen .logo {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 22px;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.5));
}

.screen .logo.brand-mark {
  font-size: 0;             /* SVG 전용 — 이모지 크기 무효화 */
  filter: none;
  opacity: 0.95;
}

.screen h1 {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* KS JARVIS VISION 워드마크 — Montserrat 계열, 넓은 자간 */
.screen h1.wordmark {
  font-family: var(--font-brand);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.24em;
  margin: 0 0 10px 0.24em;  /* 자간 보정 (마지막 글자 우측 여백 상쇄) */
  color: var(--ink);
  white-space: nowrap;
}

.screen h1.wordmark span {
  font-weight: 300;
  color: rgba(255, 255, 255, 0.75);
}

.brand-sub {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.42em;
  margin: 0 0 26px 0.42em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.screen p {
  margin: 0 0 32px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-dim);
  white-space: pre-line;   /* camera.js koMessage의 \n 개행 표시 */
  max-width: 320px;
}

/* 하단 브랜드 푸터 */
.brand-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  text-align: center;
  font-family: var(--font-brand);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: rgba(255, 255, 255, 0.34);
}

.brand-foot sup { font-size: 7px; }

/* 주 버튼 — 반전 pill (흰 바탕/검정 글씨, KS INTERNATIONAL 모티프) */
button.primary {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
  padding: 16px 44px;
  border-radius: 999px;
  background: var(--ink);
  color: #0b0b0d;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 0.08em;
  box-shadow: 0 10px 30px rgba(255, 255, 255, 0.12);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

button.primary:active { transform: scale(0.96); opacity: 0.88; }

button.primary:disabled {
  background: #2a2a2e;
  color: #6b6b70;
  box-shadow: none;
  opacity: 0.7;
  cursor: default;
}

/* ============================================================
   세로(portrait) 고정 가드 — v4
   manifest "orientation: portrait" + JS screen.orientation.lock은
   설치형 Android에서만 강제됨. iOS Safari는 회전을 막을 수 없으므로
   가로로 돌려도 레이아웃이 "옆으로 눕거나 깨지지" 않게 가드한다.
   (카메라·배지 레이어는 fixed 풀스크린이라 본래 방향 무관 —
    여기서는 시작/오류 화면과 크롬 요소의 세로 높이 부족만 보정)
   ============================================================ */

@media (orientation: landscape) {
  /* 시작/오류 화면: 세로 높이가 짧아지므로 수직 리듬 압축 (구성·순서는 동일) */
  .screen { padding-top: 16px; padding-bottom: 16px; }
  .screen .logo { margin-bottom: 12px; }
  .screen .logo.brand-mark svg { width: 100px; height: 40px; }
  .screen h1.wordmark { margin-bottom: 6px; }
  .brand-sub { margin-bottom: 14px; }
  .screen p { margin-bottom: 18px; }
  /* 스캔 안내줄: 짧은 화면에서 프레임과 겹치지 않게 살짝 올림 */
  #scan-hint { bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); }
}

/* 아주 낮은 가로 화면(폰 가로)에서는 푸터를 숨겨 버튼과 겹침 방지 */
@media (orientation: landscape) and (max-height: 440px) {
  .brand-foot { display: none; }
  .screen p { margin-bottom: 14px; font-size: 14px; }
  button.primary { padding: 13px 40px; }
}
