/* ========================================
   common.css
   공통 컴포넌트 스타일
   :root 변수, body, 유틸리티, 버튼, 배지, 로딩,
   토스트, 모달, 폼, 헤더, 햄버거메뉴, 페이지섹션,
   애니메이션, 접근성, 프린트 스타일 포함
   ======================================== */

/* ========================================
   CSS 변수 정의
   ======================================== */
:root {
  /* 주요 색상 */
  --primary-color: #667eea;
  --secondary-color: #764ba2;
  --accent-color: #ff6b6b;
  --accent-secondary: #ee5a24;

  /* 상태 색상 */
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --info-color: #3b82f6;

  /* 그레이스케일 */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* 배경 및 표면 색상 */
  --bg-primary: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-alt: #f8f9fa;

  /* 텍스트 색상 */
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --text-inverse: #ffffff;

  /* 간격 */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* 폰트 크기 */
  --font-xs: 0.75rem;
  --font-sm: 0.875rem;
  --font-base: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.25rem;
  --font-2xl: 1.5rem;
  --font-3xl: 2rem;
  --font-4xl: 2.5rem;

  /* 반지름 */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;
  --radius-full: 9999px;

  /* 그림자 */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* 전환 효과 */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* ========================================
   기본 설정 및 리셋
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Pretendard Variable', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ========================================
   유틸리티 클래스
   ======================================== */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========================================
   버튼 컴포넌트
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-full);
  font-size: var(--font-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-base);
  background: none;
  user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* 버튼 변형 - Accent (상품등록용) */
.btn-accent {
  background: linear-gradient(45deg, var(--accent-color), var(--accent-secondary));
  color: var(--text-inverse);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
  font-weight: 400;
}

.btn-accent:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-accent::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.btn-accent:hover::before {
  left: 100%;
}

/* 버튼 변형 - Primary */
.btn-primary {
  background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
  color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* 버튼 변형 - Secondary */
.btn-secondary {
  background: transparent;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-color);
  color: var(--text-inverse);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* 버튼 변형 - Danger */
.btn-danger {
  background: var(--error-color);
  color: var(--text-inverse);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* 버튼 상태 - Disabled */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--gray-200) !important;
  color: var(--gray-500) !important;
  border-color: var(--gray-300) !important;
}

.btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* 버튼 크기 변형 */
.btn-full {
  width: 100%;
}

.btn-lg {
  padding: 12px 24px;
  font-size: var(--font-base);
}

.btn-sm {
  padding: 8px 16px;
  font-size: var(--font-xs);
}

/* ========================================
   로딩 및 상태 표시 컴포넌트
   ======================================== */
.loading {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top: 4px solid var(--primary-color);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

.loading-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2xl);
  color: var(--text-secondary);
  gap: var(--spacing-md);
}

/* 빈 상태 표시 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2xl);
  color: var(--text-secondary);
  text-align: center;
}

.empty-state-icon {
  font-size: var(--font-4xl);
  margin-bottom: var(--spacing-md);
  opacity: 0.3;
}

/* ========================================
   토스트 알림 컴포넌트
   ======================================== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--gray-800);
  color: var(--text-inverse);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  font-weight: 500;
  z-index: 3000;
  transform: translateX(100%);
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  word-wrap: break-word;
}

.toast.show {
  transform: translateX(0);
}

/* 토스트 변형 */
.toast.success { background: var(--success-color); }
.toast.error { background: var(--error-color); }
.toast.warning { background: var(--warning-color); }
.toast.info { background: var(--info-color); }

/* ========================================
   배지 및 태그 컴포넌트
   ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* 서비스 배지 */
.service-badge {
  padding: 4px 8px;
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: 500;
}

.service-badge.keypaid {
  background: #e3f2fd;
  color: #0277bd;
}

.service-badge.aipaid {
  background: #f3e5f5;
  color: #7b1fa2;
}

.service-badge.system {
  background: #e8f5e8;
  color: #2e7d32;
}

/* 역할 배지 */

/* 상품 태그 */
.tag-item {
  display: inline-block;
  background: rgba(102, 126, 234, 0.1);
  color: var(--primary-color);
  padding: 4px 8px;
  border-radius: var(--radius-md);
  font-size: var(--font-xs);
  font-weight: 500;
  margin-right: 5px;
  margin-bottom: 3px;
}

/* 마켓 배지 */
.market-badge {
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}

.market-badge.domeme {
  color: var(--primary-color);
}

.market-badge.coupang {
  color: #ff6b35;
}

.market-badge.smartstore {
  color: #03c75a;
}

.market-badge.gmarket {
  color: #e74c3c;
}

.market-badge.auction {
  color: #f39c12;
}

.market-badge.lotteon {
  color: #e91e63;
}

.market-badge.elevenst {
  color: #9b59b6;
}

.market-badge.aliexpress {
  color: #ff5722;
}

.market-badge.ownerclan {
  color: #607d8b;
}

.market-badge.other {
  color: var(--text-muted);
}

/* 쿠팡 파트너스 문구 - 썸네일과 정렬 */
.coupang-partners-notice {
  font-size: var(--font-xs);
  color: #e74c3c;
  margin-bottom: var(--spacing-sm);
  margin-left: 15px; /* 썸네일(60px) + 간격(15px) */
  line-height: 1.3;
  font-weight: 500;
  animation: fadeInOut 3s ease-in-out infinite;
}

@keyframes fadeInOut {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* 품절 배지 */
.sold-out-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  margin-left: 8px;
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: 500;
  background: var(--gray-400);
  color: var(--text-inverse);
  white-space: nowrap;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ========================================
   애니메이션 정의
   ======================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalShow {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ========================================
   헤더 컴포넌트
   ======================================== */
.header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: var(--spacing-md) 0;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: var(--spacing-md);
}

/* 로고 영역 */
.logo {
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: transform var(--transition-base);
}

.logo:hover {
  transform: scale(1.02);
}

.logo-image {
  height: 40px;
  width: auto;
  max-width: 150px;
  object-fit: contain;
  transition: transform var(--transition-base);
}

/* 인증 버튼 영역 */
.auth-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-nickname {
  font-weight: 500;
  color: var(--primary-color);
}

/* ========================================
   햄버거 메뉴 컴포넌트
   ======================================== */
.hamburger-menu {
  position: relative;
}

.hamburger-btn {
  background: none;
  border: 2px solid var(--primary-color);
  color: var(--primary-color);
  padding: 8px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 18px;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.hamburger-btn:hover {
  background: var(--primary-color);
  color: var(--text-inverse);
  transform: translateY(-1px);
}

.hamburger-icon {
  font-weight: bold;
}

.hamburger-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--gray-200);
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
  animation: fadeIn var(--transition-base) ease;
}

.menu-section {
  padding: 8px 0;
}

.menu-divider {
  height: 1px;
  background: var(--gray-200);
  margin: 8px 16px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-primary);
  text-decoration: none;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.menu-item:hover {
  background: var(--gray-100);
  color: var(--primary-color);
}

.menu-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.menu-text {
  font-size: var(--font-sm);
  font-weight: 500;
}

.hamburger-dropdown.show {
  display: block;
}

/* ========================================
   페이지 섹션
   ======================================== */
.page-section {
  min-height: 100vh;
  background: var(--bg-primary);
  padding: var(--spacing-xl) 0;
}

/* ========================================
   공통 페이지 컨테이너 & 헤더
   (마이페이지, 관리자 페이지 공유)
   ======================================== */
.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-xl) 20px 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-xl);
  color: var(--text-inverse);
}

.page-header h1 {
  font-size: var(--font-4xl);
  margin: 0;
  font-weight: 700;
}

/* 보라 배경 위 "메인으로" 버튼 공통 스타일 */
.page-header .btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-inverse);
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-size: var(--font-sm);
  padding: 7px 18px;
}

.page-header .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ========================================
   모달 컴포넌트
   ======================================== */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--bg-surface);
  margin: 2% auto;
  padding: 0;
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 500px;
  max-height: 95vh;
  box-shadow: var(--shadow-xl);
  animation: modalShow var(--transition-base) ease-out;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-large {
  max-width: 700px;
  max-height: 90vh;
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg-surface);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--gray-100);
}

.modal form {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* 모달 스크롤바 스타일 */
.modal form::-webkit-scrollbar {
  width: 6px;
}

.modal form::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: var(--radius-sm);
}

.modal form::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--radius-sm);
}

.modal form::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* ========================================
   폼 컴포넌트
   ======================================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--text-primary);
  font-size: var(--font-sm);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  transition: all var(--transition-base);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
  background: var(--gray-100);
  color: var(--text-muted);
  cursor: not-allowed;
}

.auth-note {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  text-align: center;
  margin-top: 10px;
  line-height: 1.4;
}

.auth-note-highlight {
  color: var(--primary-color);
  font-weight: 500;
}

.auth-note-sub {
  color: var(--text-muted);
  font-weight: 400;
}

/* ========================================
   로그인 모달 아코디언
   ======================================== */
.auth-step-divider {
  height: 1px;
  background: var(--gray-200);
  margin: 4px 0 16px;
}

.auth-welcome {
  padding: 12px 16px;
  background: var(--gray-50, #f8f9fa);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: var(--font-sm);
  color: var(--text-primary);
  line-height: 1.5;
}

/* 2열 그리드 */
.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
  min-width: 0;
}

/* PIN 입력 */
.pin-input {
  text-align: center;
  letter-spacing: 8px;
  font-size: 20px;
  font-weight: 600;
}

.pin-forgot-link {
  display: block;
  margin-top: 6px;
  font-size: var(--font-xs);
  color: var(--text-muted);
}

/* API 설정 접이식 */
.api-settings-section {
  margin-bottom: 16px;
}

.api-settings-toggle {
  cursor: pointer;
  padding: 10px 14px;
  font-size: var(--font-sm);
  color: var(--primary-color);
  font-weight: 600;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-50, #f8f9fa);
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  transition: all var(--transition-fast);
}

.api-settings-toggle:hover {
  background: var(--gray-100);
  border-color: var(--primary-color);
}

.toggle-arrow {
  font-size: 10px;
  transition: transform var(--transition-fast);
  display: inline-block;
}

.toggle-arrow.open {
  transform: rotate(90deg);
}

.api-settings-content {
  display: none;
  padding-top: 8px;
}

.api-settings-content.open {
  display: block;
}

.api-settings-note {
  display: block;
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

.api-settings-note a {
  color: var(--primary-color);
}

/* 모바일 대응: 2열 → 1열 */
@media (max-width: 480px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

/* ========================================
   반응형 유틸리티
   ======================================== */
.hidden {
  display: none !important;
}

.visible {
  display: block !important;
}

.opacity-0 {
  opacity: 0;
}

.opacity-50 {
  opacity: 0.5;
}

.opacity-100 {
  opacity: 1;
}

/* ========================================
   인터랙션 효과
   ======================================== */
.hover-lift {
  transition: transform var(--transition-base);
}

.hover-lift:hover {
  transform: translateY(-2px);
}

.hover-scale {
  transition: transform var(--transition-base);
}

.hover-scale:hover {
  transform: scale(1.02);
}

/* ========================================
   포커스 상태 개선
   ======================================== */
.focus-ring:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.keyboard-focusable {
  position: relative;
}

.keyboard-focusable:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ========================================
   접근성 개선
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 고대비 모드 지원 */
@media (prefers-contrast: high) {
  :root {
    --gray-200: #000000;
    --gray-300: #000000;
    --text-secondary: #000000;
  }
}

/* ========================================
   프린트 스타일
   ======================================== */
@media print {
  .header,
  .add-product-btn,
  .modal,
  .toast {
    display: none !important;
  }

  .main-container {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .product-set-card {
    box-shadow: none;
    border: 1px solid #000;
    margin-bottom: 20px;
    page-break-inside: avoid;
  }
}
