/* ============================================================
   다나와 스타일 제품 비교 대시보드 - 디자인 시스템
   ============================================================ */

/* ---- Google Fonts ---- */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');

/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  /* 다크 테마 (기본) */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2333;
  --bg-card: rgba(22, 27, 34, 0.85);
  --bg-card-hover: rgba(30, 38, 50, 0.95);

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;

  --border-primary: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  --accent-purple: #8b5cf6;
  --accent-blue: #6366f1;
  --accent-cyan: #22d3ee;
  --accent-pink: #ec4899;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-yellow: #facc15;

  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
  --gradient-accent: linear-gradient(135deg, #6366f1 0%, #22d3ee 100%);
  --gradient-warm: linear-gradient(135deg, #ec4899 0%, #f97316 100%);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  --winner-bg: rgba(16, 185, 129, 0.12);
  --winner-border: rgba(16, 185, 129, 0.3);
  --loser-color: #ef4444;
  --same-opacity: 0.45;
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fa;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: rgba(255, 255, 255, 1);

  --text-primary: #1a1a2e;
  --text-secondary: #586069;
  --text-muted: #a0a7b0;

  --border-primary: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.08);

  --winner-bg: rgba(16, 185, 129, 0.08);
  --winner-border: rgba(16, 185, 129, 0.25);
  --same-opacity: 0.5;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.4s ease, color 0.4s ease;
}

/* ============================================================
   Header
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gradient-primary);
  font-size: 18px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Theme Toggle */
#theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: var(--transition);
}

#theme-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.theme-icon { font-size: 16px; }

/* ============================================================
   Category Tabs
   ============================================================ */
.category-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
}

.category-tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 4px;
}

.category-tab {
  padding: 14px 24px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-tab:hover {
  color: var(--text-primary);
}

.category-tab.active {
  color: var(--accent-blue);
}

.category-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--gradient-accent);
  border-radius: 1px;
}

.tab-icon { font-size: 18px; }

/* ============================================================
   Main Content
   ============================================================ */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ---- Search ---- */
.search-section {
  margin-bottom: 28px;
}

.search-container {
  position: relative;
  max-width: 600px;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 0 16px;
  transition: var(--transition);
  backdrop-filter: blur(10px);
}

.search-input-wrapper:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.search-icon {
  font-size: 18px;
  margin-right: 10px;
  opacity: 0.5;
}

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 0;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}

#search-input::placeholder {
  color: var(--text-muted);
}

/* Search Dropdown */
#search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

#search-dropdown.hidden { display: none; }

.search-result-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  gap: 12px;
  transition: var(--transition);
  border-bottom: 1px solid var(--border-primary);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-tertiary); }
.search-result-item.in-compare { background: var(--winner-bg); }

.sr-icon { font-size: 24px; }
.sr-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sr-name { font-weight: 600; font-size: 14px; }
.sr-brand { font-size: 12px; color: var(--text-secondary); }
.sr-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  color: var(--accent-blue);
}
.search-result-item.in-compare .sr-badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}

.search-no-result {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   Product Grid
   ============================================================ */
.product-grid-section {
  margin-bottom: 40px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title-icon { font-size: 20px; }

#product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* Product Card */
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  backdrop-filter: blur(10px);
  animation: fadeInUp 0.5s ease forwards;
  opacity: 0;
}

.product-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.product-card.in-compare {
  border-width: 2px;
}

.card-compare-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: var(--transition);
}

.card-compare-badge.active {
  background: var(--gradient-accent);
  color: white;
}

.card-image {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  margin-bottom: 14px;
}

.card-image-placeholder {
  font-size: 48px;
  opacity: 0.7;
}

.card-body { display: flex; flex-direction: column; gap: 6px; }

.card-brand {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-blue);
}

.card-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.card-price {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-purple);
}

.price-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.card-specs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-primary);
}

.quick-spec {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.qs-label { color: var(--text-secondary); }
.qs-value { font-weight: 600; color: var(--text-primary); }

/* ============================================================
   Compare Section
   ============================================================ */
.compare-section {
  margin-bottom: 40px;
}

/* Compare Slots */
.compare-slots-wrapper {
  margin-bottom: 28px;
}

#compare-slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.compare-slot {
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
  transition: var(--transition);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.compare-slot.filled {
  background: var(--bg-card);
  border: 2px solid var(--slot-color, var(--border-primary));
  box-shadow: 0 0 15px color-mix(in srgb, var(--slot-color, transparent) 20%, transparent);
}

.compare-slot.empty {
  background: var(--bg-tertiary);
  border: 2px dashed var(--border-primary);
  opacity: 0.6;
}

.slot-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.slot-remove:hover {
  background: var(--accent-red);
  color: white;
}

.slot-icon { font-size: 28px; margin-bottom: 6px; }
.slot-info { text-align: center; }
.slot-brand { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; }
.slot-name { font-size: 13px; font-weight: 700; margin: 2px 0; }
.slot-price { font-size: 12px; color: var(--accent-purple); font-weight: 600; }
.slot-color-bar {
  position: absolute;
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 3px;
  border-radius: 2px;
}

.slot-empty-icon {
  font-size: 28px;
  color: var(--text-muted);
  font-weight: 300;
}

.slot-empty-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- Compare Toolbar ---- */
#compare-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  backdrop-filter: blur(10px);
}

#compare-toolbar.hidden { display: none; }

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-btn {
  padding: 8px 16px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.toolbar-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.toolbar-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: white;
}

.toolbar-btn.danger {
  color: var(--accent-red);
  border-color: rgba(239, 68, 68, 0.3);
}

.toolbar-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================================
   Compare Table
   ============================================================ */
.compare-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.compare-table thead {
  position: sticky;
  top: 64px;
  z-index: 10;
}

.compare-table th,
.compare-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-primary);
}

.spec-header-cell {
  background: var(--bg-secondary) !important;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 160px;
  position: sticky;
  left: 0;
  z-index: 5;
}

.product-col-header {
  background: var(--bg-secondary) !important;
  min-width: 200px;
}

.col-product-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
}

.col-product-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Section Headers */
.section-header td {
  background: var(--bg-tertiary) !important;
  padding: 0;
  border: none;
}

.section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.section-arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.section-arrow.collapsed {
  transform: rotate(-90deg);
}

.section-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: auto;
}

/* Spec Rows */
.spec-row {
  transition: var(--transition);
}

.spec-row:hover {
  background: var(--bg-tertiary);
}

.spec-row.hidden {
  display: none;
}

.spec-row.same-value {
  opacity: var(--same-opacity);
}

.spec-row.diff-value {
  opacity: 1;
}

.spec-name-cell {
  position: sticky;
  left: 0;
  background: var(--bg-secondary);
  z-index: 3;
  font-weight: 500;
  color: var(--text-secondary);
}

.spec-row:hover .spec-name-cell {
  background: var(--bg-tertiary);
}

.spec-value-cell {
  font-weight: 500;
}

.spec-value {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cell-winner {
  background: var(--winner-bg);
}

.cell-winner .spec-value {
  color: var(--accent-green);
  font-weight: 700;
}

.winner-icon {
  font-size: 14px;
}

.cell-loser .spec-value {
  color: var(--loser-color);
  opacity: 0.8;
}

/* Compare Stats */
.compare-stats {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  border-top: 1px solid var(--border-primary);
  margin-top: 4px;
}

.compare-stats strong {
  color: var(--accent-blue);
}

/* Compare Empty */
.compare-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.compare-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.compare-empty h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.compare-empty p {
  font-size: 14px;
}

/* ============================================================
   Radar Chart
   ============================================================ */
#chart-section {
  margin-bottom: 32px;
}

#chart-section.hidden { display: none; }

.chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(10px);
}

#radar-canvas {
  width: 100%;
  height: 360px;
  display: block;
}

#radar-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ============================================================
   Price Chart
   ============================================================ */
.price-chart {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(10px);
}

.price-bars {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.price-bar-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.price-bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.price-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.lowest-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
}

.price-bar-track {
  height: 32px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.price-bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 12px;
  min-width: fit-content;
  width: 0;
}

.price-bar-value {
  font-size: 12px;
  font-weight: 700;
  color: white;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ============================================================
   Table Container - Scrollable
   ============================================================ */
.table-scroll-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
}

.table-scroll-wrapper::-webkit-scrollbar {
  height: 6px;
}

.table-scroll-wrapper::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

.table-scroll-wrapper::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes barGrow {
  from { width: 0; }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  #compare-slots {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
  }

  .theme-label { display: none; }

  .category-tabs {
    padding: 0 16px;
    overflow-x: auto;
  }

  .category-tab {
    padding: 12px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  .main {
    padding: 16px;
  }

  #product-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
  }

  #compare-slots {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .compare-slot {
    min-height: 100px;
    padding: 12px;
  }

  #compare-toolbar {
    flex-direction: column;
    gap: 8px;
  }

  .toolbar-left, .toolbar-right {
    width: 100%;
    justify-content: center;
  }

  #radar-canvas {
    height: 280px;
  }

  .spec-header-cell {
    min-width: 120px;
  }

  .product-col-header {
    min-width: 150px;
  }
}

@media (max-width: 480px) {
  .logo-text { display: none; }

  #product-grid {
    grid-template-columns: 1fr;
  }

  #compare-slots {
    grid-template-columns: 1fr 1fr;
  }
}
