:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-900: #111827;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Pretendard', 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 18px; font-weight: 700; color: var(--primary); }
#last-updated { font-size: 12px; color: var(--gray-400); }

/* ── Container ───────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab-btn {
  height: 40px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid var(--gray-200);
  border-radius: 100px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--gray-600);
}
.tab-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* ── Search bar ──────────────────────────────────────────────── */
.search-bar { margin-bottom: 12px; }
#search-input {
  width: 100%;
  max-width: 400px;
  padding: 9px 14px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
}
#search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

/* ── Sort bar ────────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.sort-bar span { font-size: 13px; color: var(--gray-600); font-weight: 500; }
.sort-btn {
  padding: 6px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--gray-600);
  font-family: inherit;
}
.sort-btn:hover { background: var(--gray-100); }
.sort-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

/* ── Filter bar ──────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.filter-group { display: flex; align-items: center; gap: 6px; row-gap: 6px; flex-wrap: wrap; }
.filter-label { font-size: 13px; font-weight: 600; color: var(--gray-600); white-space: nowrap; }
.filter-btn {
  height: 28px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
  color: var(--gray-600);
  font-family: inherit;
}
.filter-group .filter-btn { margin-bottom: 0; }
.filter-btn:hover { background: var(--gray-100); }
.filter-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.filter-sep { color: var(--gray-300); font-size: 16px; margin: 0 2px; user-select: none; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--gray-600);
  user-select: none;
}
.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.toggle-text { font-weight: 500; }

/* ── Stats bar ───────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--gray-600);
  flex-wrap: wrap;
}
.stats-bar strong { color: var(--gray-900); }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--gray-50); border-bottom: 2px solid var(--gray-200); }
th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
th.center, td.center { text-align: center; }
th.right, td.right { text-align: right; }
tbody tr { border-bottom: 1px solid var(--gray-100); transition: background 0.1s; }
tbody tr:hover { background: #eff6ff; }
tbody tr:last-child { border-bottom: none; }
td { padding: 12px 16px; vertical-align: top; }

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  background: var(--gray-100);
  color: var(--gray-600);
}
.rank-badge.top1 { background: #fbbf24; color: #78350f; }
.rank-badge.top2 { background: #94a3b8; color: #1e293b; }
.rank-badge.top3 { background: #c2813e; color: #fff; }

.product-name { font-weight: 500; font-size: 13px; max-width: 320px; word-break: break-all; }
.product-name small { display: block; font-size: 11px; color: var(--gray-400); font-weight: 400; margin-top: 2px; }
.price { font-weight: 600; font-size: 14px; white-space: nowrap; }
.price-null { color: var(--gray-400); font-size: 12px; }
.diff { font-size: 13px; font-weight: 600; white-space: nowrap; }
.diff.cheaper { color: var(--success); }
.diff.expensive { color: var(--danger); }
.diff.same { color: var(--gray-400); }
.no-match { font-size: 12px; color: var(--gray-400); font-style: italic; }

/* ── Loading & Error ─────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px;
  color: var(--gray-600);
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 16px 20px;
  color: #991b1b;
}

/* ── Hover popup ─────────────────────────────────────────────── */
.hover-popup {
  position: absolute;
  z-index: 999;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  padding: 12px;
  width: 360px;
  pointer-events: auto;
}
.hover-popup-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 8px;
  word-break: break-all;
  line-height: 1.4;
}
.hover-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  font-size: 13px;
  color: var(--gray-400);
}

/* ── Trend section ───────────────────────────────────────────── */
.trend-header {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.trend-cat-tabs { display: flex; gap: 8px; }
.trend-cat-btn {
  padding: 6px 18px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-600);
  font-family: inherit;
  transition: all 0.12s;
}
.trend-cat-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

.trend-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.trend-select {
  flex: 1;
  min-width: 200px;
  max-width: 500px;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  cursor: pointer;
  outline: none;
}
.trend-select:focus { border-color: var(--primary); }
.trend-days-group { display: flex; gap: 6px; }
.days-btn {
  padding: 6px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  color: var(--gray-600);
  font-family: inherit;
  transition: all 0.12s;
}
.days-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

.trend-chart-wrap {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-height: 480px; /* 더 넓은 세로 공간 확보 */
  display: flex;
  align-items: center;
  justify-content: center;
}

#trend-chart {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  width: 100% !important;
  height: 520px !important; /* 더 넓게 보여주기 */
}

.trend-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 15px;
  line-height: 2;
}

/* ── Footer ─────────────────────────────────────────────────── */
.site-footer {
  margin: 18px auto 24px;
  text-align: center;
}

.github-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--gray-600);
  text-decoration: none;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  background: #fff;
  transition: all 0.12s;
  font-size: 13px;
}

.github-link:hover {
  color: var(--gray-900);
  border-color: var(--gray-400);
  background: var(--gray-50);
}

.github-mark {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .product-name { max-width: 180px; }
  th:nth-child(5), td:nth-child(5) { display: none; }
  .hover-popup { display: none !important; }
  #trend-chart { height: 260px !important; }
  .github-link {
    max-width: calc(100vw - 32px);
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
  }
}
