/* ===== 기본 변수 ===== */
:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --gray-border: #e5e7eb;
  --text: #111827;
  --text-sub: #6b7280;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

/* ===== 리셋 & 기본 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo',
               'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
img, video { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ===== 레이아웃 ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.page-wrap { padding-top: 70px; padding-bottom: 40px; }

/* ===== 헤더 ===== */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--gray-border);
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; max-width: 1100px; margin: 0 auto; padding: 0 16px;
}
.site-logo {
  font-size: 1.2rem; font-weight: 700; color: var(--primary);
  display: flex; align-items: center; gap: 8px;
}
.site-logo span { font-size: 1.4rem; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ===== 버튼 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem;
  font-weight: 600; border: none; transition: all 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost:hover { background: var(--primary-light); }
.btn-gray { background: var(--gray-light); color: var(--text); }
.btn-gray:hover { background: var(--gray-border); }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; border-radius: 6px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== 상태 뱃지 ===== */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.02em;
}
.badge-sale, .badge-forsale { background: var(--success-light); color: var(--success); }
.badge-nego, .badge-intalks { background: var(--warning-light); color: var(--warning); }
.badge-reserve, .badge-reserved { background: var(--primary-light); color: var(--primary-dark); }
.badge-sold { background: var(--gray-light); color: var(--gray); }

/* ===== 카드 ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}

/* ===== 상품 그리드 ===== */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding: 24px 0;
}
.item-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column;
}
.item-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.item-card.sold-out { opacity: 0.65; }
.item-thumb {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
  background: var(--gray-light);
}
.item-thumb-placeholder {
  width: 100%; aspect-ratio: 4/3; background: var(--gray-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; color: var(--gray-border);
}
.item-info { padding: 14px 16px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.item-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-price { font-size: 1.15rem; font-weight: 700; color: var(--primary); }
.item-desc {
  font-size: 0.85rem; color: var(--text-sub);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.item-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 8px;
}
.item-meta { font-size: 0.78rem; color: var(--gray); }

/* ===== 갤러리 ===== */
.gallery-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.gallery-main { width: 100%; aspect-ratio: 4/3; object-fit: contain; }
.gallery-main video { width: 100%; aspect-ratio: 4/3; object-fit: contain; }
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,0.5); color: white; border: none;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s;
}
.gallery-nav:hover { background: rgba(0,0,0,0.75); }
.gallery-prev { left: 10px; }
.gallery-next { right: 10px; }
.gallery-counter {
  position: absolute; bottom: 10px; right: 14px;
  background: rgba(0,0,0,0.55); color: white;
  font-size: 0.8rem; padding: 3px 10px; border-radius: 999px;
}
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.gallery-thumbs::-webkit-scrollbar { height: 4px; }
.gallery-thumbs::-webkit-scrollbar-track { background: var(--gray-light); border-radius: 2px; }
.gallery-thumbs::-webkit-scrollbar-thumb { background: var(--gray-border); border-radius: 2px; }
.gallery-thumb {
  width: 70px; height: 52px; object-fit: cover; border-radius: 6px;
  cursor: pointer; opacity: 0.6; flex-shrink: 0;
  border: 2px solid transparent; transition: all 0.15s;
}
.gallery-thumb.active { opacity: 1; border-color: var(--primary); }

/* ===== 폼 ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.form-label .required { color: var(--danger); }
.form-input, .form-textarea, .form-select {
  padding: 10px 14px; border: 1.5px solid var(--gray-border);
  border-radius: 8px; font-size: 0.95rem; color: var(--text);
  background: white; transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-hint { font-size: 0.8rem; color: var(--text-sub); }

/* ===== 모달 ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 16px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  transform: scale(0.95); transition: transform 0.2s;
}
.modal-backdrop.open .modal { transform: scale(1); }
.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--gray-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.4rem; color: var(--gray);
  cursor: pointer; line-height: 1; padding: 2px;
}
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--gray-border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ===== 채팅 ===== */
.chat-wrap {
  display: flex; flex-direction: column;
  border: 1.5px solid var(--gray-border); border-radius: var(--radius);
  overflow: hidden;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 200px; max-height: 400px;
  background: #f9fafb;
}
.chat-bubble-wrap { display: flex; flex-direction: column; }
.chat-bubble-wrap.me { align-items: flex-end; }
.chat-bubble-wrap.other { align-items: flex-start; }
.chat-name { font-size: 0.78rem; color: var(--gray); margin-bottom: 4px; }
.chat-bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 12px;
  font-size: 0.92rem; line-height: 1.5; word-break: break-word;
}
.chat-bubble-wrap.me .chat-bubble { background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.chat-bubble-wrap.other .chat-bubble { background: white; border: 1px solid var(--gray-border); border-bottom-left-radius: 4px; }
.chat-offer {
  display: inline-block; background: rgba(255,255,255,0.25);
  padding: 3px 10px; border-radius: 6px; font-weight: 700; margin-top: 4px;
  font-size: 0.88rem;
}
.chat-bubble-wrap.other .chat-offer { background: var(--primary-light); color: var(--primary-dark); }
.chat-time { font-size: 0.72rem; color: var(--gray); margin-top: 4px; }
.chat-address {
  background: #fef9c3; border: 1px solid #fbbf24; border-radius: 10px;
  padding: 12px 16px; font-size: 0.9rem; display: flex; align-items: flex-start; gap: 10px;
}
.chat-address-icon { font-size: 1.3rem; flex-shrink: 0; }
.chat-address-content { flex: 1; }
.chat-address-label { font-size: 0.78rem; font-weight: 700; color: #92400e; margin-bottom: 4px; }
.chat-address-copy {
  background: #fbbf24; color: #78350f; border: none; padding: 4px 12px;
  border-radius: 6px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
  margin-top: 8px;
}
.chat-address-copy:hover { background: #f59e0b; }
.chat-input-wrap {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--gray-border); background: white;
  align-items: flex-end;
}
.chat-input {
  flex: 1; padding: 10px 12px; border: 1.5px solid var(--gray-border);
  border-radius: 8px; font-size: 0.9rem; resize: none;
  min-height: 42px; max-height: 120px; line-height: 1.5;
}
.chat-input:focus { outline: none; border-color: var(--primary); }
.chat-send { padding: 10px 16px; border-radius: 8px; flex-shrink: 0; }

/* ===== Q&A ===== */
.qa-item {
  border: 1.5px solid var(--gray-border); border-radius: 10px;
  overflow: hidden; margin-bottom: 12px;
}
.qa-question { padding: 14px 16px; background: white; }
.qa-question-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.qa-author { font-size: 0.82rem; font-weight: 600; color: var(--primary); }
.qa-date { font-size: 0.78rem; color: var(--gray); }
.qa-text { font-size: 0.92rem; color: var(--text); }
.qa-answer { padding: 14px 16px; background: var(--gray-light); border-top: 1px solid var(--gray-border); }
.qa-answer-label { font-size: 0.78rem; font-weight: 700; color: var(--success); margin-bottom: 6px; }
.qa-answer-text { font-size: 0.92rem; color: var(--text); }
.qa-pending { padding: 10px 16px; background: #fffbeb; border-top: 1px solid var(--gray-border); }
.qa-pending-text { font-size: 0.82rem; color: var(--warning); }

/* ===== 알림 ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1f2937; color: white; padding: 12px 24px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 500; box-shadow: var(--shadow-lg);
  z-index: 1000; transition: transform 0.3s ease; white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== 빈 상태 ===== */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-sub);
}
.empty-icon { font-size: 3.5rem; margin-bottom: 16px; }
.empty-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-desc { font-size: 0.9rem; }

/* ===== 로딩 ===== */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--gray-border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 구분선 ===== */
.divider { border: none; border-top: 1.5px solid var(--gray-border); margin: 24px 0; }

/* ===== 섹션 타이틀 ===== */
.section-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
}
.section-title .cnt {
  background: var(--primary); color: white;
  font-size: 0.75rem; padding: 2px 8px; border-radius: 999px;
}

/* ===== 반응형 ===== */
@media (max-width: 640px) {
  .items-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .page-wrap { padding-top: 65px; }
  .modal { max-height: 95vh; }
  .btn-lg { padding: 13px 22px; }
  .chat-messages { max-height: 300px; }
}
@media (max-width: 380px) {
  .items-grid { grid-template-columns: 1fr; }
}

/* ===== 스크롤바 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--gray-light); }
::-webkit-scrollbar-thumb { background: var(--gray-border); border-radius: 3px; }

/* ===== 미디어 업로드 ===== */
.upload-area {
  border: 2px dashed var(--gray-border); border-radius: 10px;
  padding: 32px; text-align: center; cursor: pointer;
  transition: all 0.15s; background: var(--gray-light);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary); background: var(--primary-light);
}
.upload-icon { font-size: 2.5rem; margin-bottom: 8px; }
.upload-text { font-size: 0.9rem; color: var(--gray); }
.upload-hint { font-size: 0.78rem; color: var(--gray); margin-top: 4px; }

/* ===== 미디어 프리뷰 그리드 ===== */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px; margin-top: 12px;
}
.media-thumb-wrap {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--gray-border);
}
.media-thumb-img, .media-thumb-video {
  width: 100%; height: 100%; object-fit: cover;
}
.media-thumb-del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(220,38,38,0.85); color: white; border: none;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 0.8rem; display: flex; align-items: center; justify-content: center;
  cursor: pointer; line-height: 1;
}
.media-thumb-del:hover { background: var(--danger); }
.media-thumb-badge {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(0,0,0,0.6); color: white;
  font-size: 0.65rem; padding: 1px 6px; border-radius: 4px;
}

/* ===== 상품 상세 레이아웃 ===== */
.item-detail-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  align-items: start; padding: 24px 0;
}
@media (max-width: 768px) {
  .item-detail-layout { grid-template-columns: 1fr; gap: 20px; }
}
