/* ============================================================
   굿즈 판매 사이트 - 전 페이지 공용 스타일
   ============================================================
   "모바일 우선" 으로 작성했습니다.
   - 아무 조건 없는 스타일 = 폰 화면 기준
   - @media (min-width: 640px)  = 태블릿부터 덧붙이는 스타일
   - @media (min-width: 1024px) = PC부터 덧붙이는 스타일
   - 손가락으로 누르는 곳은 높이 44px 이상으로 둡니다.
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a1d23;
  --text-muted: #5b6474;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #059669;
  --warning: #b45309;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --max-width: 1100px;
  --tap: 44px;               /* 최소 터치 높이 */
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;      /* 한글 단어 중간에서 줄이 끊기지 않게 */
  overflow-wrap: anywhere;
}

img { max-width: 100%; display: block; }

/* ---------- 레이아웃 ---------- */

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

main.container {
  padding-top: 20px;
  padding-bottom: 56px;
}

/* ---------- 헤더 ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header .inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.site-header .brand {
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

/* 폰: 메뉴가 브랜드 아래 한 줄을 통째로 쓰고, 넘치면 옆으로 밀어서 봅니다 */
.site-header nav {
  order: 3;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-header nav::-webkit-scrollbar { display: none; }

.site-header nav a {
  flex: none;
  color: var(--text-muted);
  text-decoration: none;
  min-height: var(--tap);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}

.site-header nav a.active {
  color: var(--primary);
  background: #eef2ff;
}

.site-header nav .btn { flex: none; margin-left: auto; }

.user-chip {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-chip.admin {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: var(--primary);
  font-weight: 600;
}

/* 폰에서는 이메일 칩을 브랜드 옆에 둡니다 */
.site-header .user-chip { margin-left: auto; }

/* ---------- 제목 ---------- */

.page-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.page-desc {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 15px;
}

/* ---------- 카드 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { font-size: 20px; font-weight: 800; }
.stat-value.highlight { color: var(--primary); }

/* ---------- 상품 그리드 ---------- */

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

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.product-thumb {
  aspect-ratio: 1 / 1;
  background: #f1f2f5;
  display: grid;
  place-items: center;
  font-size: 44px;
  line-height: 1;
  overflow: hidden;
}

.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

/* 긴 상품명은 두 줄까지만 보여줍니다 */
.product-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-desc {
  color: var(--text-muted);
  font-size: 13px;
  flex: 1;
}

.product-price { font-weight: 800; font-size: 17px; margin-top: 2px; }
.product-stock { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

/* ---------- 결제 화면 ---------- */

/* 폰: 상품 → 결제수단 → 금액·결제버튼 (위에서 아래로 한 번에 진행) */
.checkout-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "item"
    "widgets"
    "pay";
  gap: 16px;
  align-items: start;
}

.checkout-item    { grid-area: item; }
.checkout-widgets { grid-area: widgets; min-width: 0; }
.checkout-pay     { grid-area: pay; }
.checkout-item .form-row { margin-bottom: 0; }

.order-item {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.order-item .product-thumb {
  width: 72px;
  height: 72px;
  flex: none;
  border-radius: 10px;
  font-size: 30px;
}

.order-item-name { font-weight: 700; line-height: 1.4; }
.order-item-desc { font-size: 13px; color: var(--text-muted); }

/* ---------- 버튼 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.btn:active:not(:disabled) { background: var(--primary-hover); }

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

.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 16px; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:active:not(:disabled) { background: var(--bg); }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }

/* 키보드로 이동할 때 어디에 있는지 잘 보이게 */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.45);
  outline-offset: 2px;
}

/* ---------- 폼 ---------- */

.form-row { margin-bottom: 16px; }

.form-row label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* 글자 크기 16px 미만이면 아이폰이 입력할 때 화면을 확대해 버립니다 */
.form-row input,
.form-row select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- 탭 ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 20px;
}

.tabs button {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
}

.tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 420px;
  margin: 8px auto 0;
}

/* ---------- 알림 메시지 ---------- */

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* ---------- 주문 내역 표 ---------- */
/* 폰: 표 대신 "주문 1건 = 카드 1장" 으로 보여줍니다.
   각 칸의 제목은 td 의 data-label 값을 앞에 붙여서 표시합니다. */

.table-wrap {
  background: transparent;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

table thead { display: none; }

table tbody tr {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  margin-bottom: 10px;
}

table tbody td {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  text-align: right;
}

table tbody td::before {
  content: attr(data-label);
  flex: none;
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
}

/* 상품명 칸은 카드 제목처럼 크게 */
table tbody td.cell-title {
  display: block;
  text-align: left;
  font-weight: 700;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

table tbody td.cell-title::before { content: none; }

.order-code { font-size: 12px; font-weight: 400; color: var(--text-muted); }

.num { font-variant-numeric: tabular-nums; }

/* ---------- 상태 배지 ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-DONE     { background: #ecfdf5; color: var(--success); }
.badge-PENDING  { background: #fffbeb; color: var(--warning); }
.badge-FAILED   { background: #fef2f2; color: var(--danger); }
.badge-CANCELED { background: #f3f4f6; color: var(--text-muted); }

.fail-reason { font-size: 12px; color: var(--danger); margin-top: 3px; }

/* ---------- 상태 표시 ---------- */

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

.loading {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.7s linear infinite;
}

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

/* ---------- 결제 결과 화면 ---------- */

.result {
  max-width: 480px;
  margin: 24px auto;
  text-align: center;
}

.result .icon { font-size: 52px; margin-bottom: 12px; }
.result h1 { font-size: 21px; margin: 0 0 8px; }
.result p { color: var(--text-muted); margin: 0 0 24px; }

.summary {
  text-align: left;
  border-top: 1px solid var(--border);
  margin-top: 20px;
  padding-top: 16px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  font-size: 15px;
}

.summary-row span:first-child { color: var(--text-muted); flex: none; }
.summary-row span:last-child { font-weight: 600; text-align: right; }

.summary-row.total {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 14px;
  font-size: 17px;
}

.summary-row.total span:last-child { color: var(--primary); font-weight: 800; }

/* ---------- 학습용 프로젝트 안내 띠 ---------- */

.demo-banner {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  text-align: center;
  padding: 6px 16px;
}

/* ============================================================
   태블릿 (640px 이상)
   ============================================================ */

@media (min-width: 640px) {
  main.container { padding-top: 32px; padding-bottom: 64px; }

  /* 메뉴가 브랜드와 같은 줄 오른쪽으로 */
  .site-header .inner { flex-wrap: nowrap; gap: 16px; padding: 10px 16px; }
  .site-header nav { order: 0; width: auto; margin-left: auto; overflow: visible; }
  .site-header .user-chip { margin-left: 0; max-width: 220px; }
  .site-header nav .btn { margin-left: 0; }

  .page-title { font-size: 26px; }
  .page-desc { margin-bottom: 28px; }
  .card { padding: 24px; }

  .stats { display: flex; flex-wrap: wrap; gap: 40px; margin-bottom: 20px; }
  .stat-value { font-size: 22px; }

  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .product-body { padding: 14px 16px 16px; }
  .product-name { font-size: 16px; }
  .product-price { font-size: 18px; }

  .auth-card { margin-top: 24px; }
  .result { margin: 48px auto; }

  /* 주문 내역: 다시 진짜 표로 */
  .table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }

  table { font-size: 14px; }
  table thead { display: table-header-group; }

  thead th {
    text-align: left;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    white-space: nowrap;
  }

  table tbody tr {
    display: table-row;
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }

  table tbody td,
  table tbody td.cell-title {
    display: table-cell;
    text-align: left;
    font-weight: inherit;
    padding: 12px 14px;
    margin: 0;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }

  table tbody td::before { content: none; }
  table tbody tr:last-child td { border-bottom: none; }

  th.num, td.num { text-align: right; white-space: nowrap; }
}

/* ============================================================
   PC (1024px 이상)
   ============================================================ */

@media (min-width: 1024px) {
  .product-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }

  .checkout-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "widgets item"
      "widgets pay";
    gap: 16px 24px;
  }
}

/* ============================================================
   마우스가 있는 기기에서만 hover 효과
   (폰에서 손가락을 뗀 뒤에도 효과가 남는 현상 방지)
   ============================================================ */

@media (hover: hover) {
  .product-card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
  .product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.1);
  }
  .site-header nav a:hover { background: var(--bg); color: var(--text); }
  .btn:hover:not(:disabled) { background: var(--primary-hover); }
  .btn-secondary:hover:not(:disabled) { background: var(--bg); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
