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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --accent: #7c3aed;
  --green: #059669;
  --orange: #d97706;
  --red: #dc2626;
  --text: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.1);
}

body {
  font-family: 'Apple SD Gothic Neo', 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1e40af 0%, #7c3aed 100%);
  color: white;
  padding: 28px 20px 24px;
  text-align: center;
}
.header-inner { max-width: 900px; margin: 0 auto; }
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.logo-icon { font-size: 1.9rem; }
.logo-text { font-size: 1.75rem; color: rgba(255,255,255,.9); }
.logo-text strong { color: #fff; font-weight: 800; }
.header-sub { font-size: .9rem; color: rgba(255,255,255,.72); }

/* ── Main ───────────────────────────────────────── */
.main-wrap { flex: 1; max-width: 1080px; width: 100%; margin: 0 auto; padding: 28px 16px 48px; }

/* ── Section title ──────────────────────────────── */
.section-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}
.section-title::before {
  content: ''; display: inline-block; width: 4px; height: 18px;
  background: var(--primary); border-radius: 2px;
}

/* ── Type Grid ──────────────────────────────────── */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.type-card {
  background: var(--white); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); transition: all .16s ease;
}
.type-card:hover { border-color: var(--primary); background: var(--primary-light); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.type-card.active { border-color: var(--primary); background: var(--primary-light); }
.type-card-icon { font-size: 1.7rem; flex-shrink: 0; }
.type-card-info {}
.type-card-label { font-size: .9rem; font-weight: 700; color: var(--text); }
.type-card-source { font-size: .72rem; color: var(--text-sub); margin-top: 2px; }

/* ── Search Card ────────────────────────────────── */
.search-section { margin-bottom: 24px; }
.search-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.search-header {
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  color: white; padding: 13px 20px;
  display: flex; align-items: center; gap: 10px;
}
.search-type-icon { font-size: 1.4rem; }
.search-type-label { font-size: .95rem; font-weight: 700; flex: 1; }
.search-source-badge {
  font-size: .72rem; background: rgba(255,255,255,.2);
  border-radius: 20px; padding: 3px 10px; color: rgba(255,255,255,.9);
}
.search-form { padding: 18px 20px; }
.input-row { margin-bottom: 12px; }
.search-input {
  width: 100%; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: .95rem; font-family: inherit;
  color: var(--text); background: var(--bg); resize: none; transition: border-color .15s;
  line-height: 1.5;
}
.search-input:focus { outline: none; border-color: var(--primary); background: var(--white); }

/* 정렬 */
.sort-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.sort-label { font-size: .83rem; font-weight: 600; color: var(--text-sub); }
.sort-opt { font-size: .83rem; color: var(--text); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.sort-opt input { accent-color: var(--primary); }

.search-actions { display: flex; justify-content: space-between; align-items: center; }
.btn-back {
  background: none; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: .875rem; color: var(--text-sub); cursor: pointer; transition: all .15s;
}
.btn-back:hover { border-color: var(--text-sub); color: var(--text); }
.btn-search {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white; border: none; border-radius: var(--radius-sm);
  padding: 11px 28px; font-size: .95rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(37,99,235,.3); transition: opacity .15s, transform .15s;
}
.btn-search:hover { opacity: .9; transform: translateY(-1px); }
.btn-search:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Loading ─────────────────────────────────────── */
.loading-wrap { text-align: center; padding: 56px 20px; }
.loading-spinner {
  width: 44px; height: 44px; border: 4px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 1rem; font-weight: 600; color: var(--text-sub); }

/* ── Result ─────────────────────────────────────── */
.result-section { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

.result-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 18px;
}
.result-title { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.result-meta { font-size: .82rem; color: var(--text-sub); }
.btn-reset {
  background: var(--white); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 16px; font-size: .85rem; color: var(--text-sub); cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-reset:hover { border-color: var(--primary); color: var(--primary); }

/* ── Result Sort Bar ────────────────────────────── */
.result-sort-bar {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.result-sort-label {
  font-size: .8rem; font-weight: 600; color: var(--text-sub); margin-right: 2px;
}
.result-sort-btn {
  background: var(--white); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 5px 14px;
  font-size: .82rem; color: var(--text-sub); cursor: pointer;
  transition: all .14s; font-family: inherit;
}
.result-sort-btn:hover { border-color: var(--primary); color: var(--primary); }
.result-sort-btn.active {
  background: var(--primary); border-color: var(--primary);
  color: white; font-weight: 600;
}

/* ── Sort Fallback Notice ────────────────────────── */
.sort-fallback-notice {
  background: #fffbeb; border: 1.5px solid #f59e0b;
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: .83rem; color: #92400e; margin-bottom: 14px;
}

/* ── Query Refine ───────────────────────────────── */
.query-refine {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  background: var(--white); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  margin-bottom: 16px;
}
.query-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.query-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--primary-light); color: var(--primary);
  border: 1px solid #bfdbfe; border-radius: 20px;
  padding: 4px 10px 4px 12px; font-size: .82rem; font-weight: 600;
}
.query-tag-remove {
  background: none; border: none; cursor: pointer;
  color: var(--primary); font-size: 1rem; line-height: 1;
  padding: 0; display: flex; align-items: center;
  opacity: .6; transition: opacity .12s;
}
.query-tag-remove:hover { opacity: 1; }
.query-add { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.query-add-input {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: .82rem; font-family: inherit;
  width: 130px; color: var(--text); background: var(--bg);
  transition: border-color .15s;
}
.query-add-input:focus { outline: none; border-color: var(--primary); background: var(--white); }
.btn-add-tag {
  background: var(--primary); color: white; border: none;
  border-radius: var(--radius-sm); padding: 5px 12px;
  font-size: .82rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: background .15s;
}
.btn-add-tag:hover { background: var(--primary-dark); }

/* ── Result Grid ────────────────────────────────── */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

/* ── Product Card ───────────────────────────────── */
.product-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: all .16s ease;
  display: flex; flex-direction: column;
}
.product-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.product-img-wrap {
  width: 100%; aspect-ratio: 1/1; overflow: hidden;
  background: #f1f5f9; position: relative;
}
.product-img-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .3s ease;
}
.product-card:hover .product-img-wrap img { transform: scale(1.04); }
.product-img-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center;
  justify-content: center; font-size: 3rem; color: #cbd5e1;
}

.product-body { padding: 13px 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.product-title {
  font-size: .88rem; font-weight: 600; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.45;
}
.product-price { font-size: 1.15rem; font-weight: 800; color: var(--red); }
.product-price-unit { font-size: .78rem; font-weight: 400; color: var(--text-sub); margin-left: 2px; }
.product-mall {
  font-size: .78rem; color: var(--text-sub);
  display: flex; align-items: center; gap: 5px; margin-top: auto;
}
.mall-badge {
  display: inline-block; background: var(--primary-light); color: var(--primary);
  border-radius: 4px; padding: 1px 6px; font-size: .72rem; font-weight: 600;
}
.product-link {
  display: block; text-align: center; background: var(--primary);
  color: white; text-decoration: none; padding: 9px;
  font-size: .85rem; font-weight: 600; transition: background .15s;
  margin-top: 6px; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.product-link:hover { background: var(--primary-dark); }

/* ── Place Card (카카오) ─────────────────────────── */
.place-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); transition: all .16s ease;
  display: flex; flex-direction: column; gap: 8px;
}
.place-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.place-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.place-name { font-size: .97rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.place-num {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: white;
  font-size: .72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.place-category {
  display: inline-block; font-size: .73rem; color: var(--accent);
  background: #f5f3ff; border-radius: 4px; padding: 2px 7px;
  font-weight: 600; align-self: flex-start;
}
.place-address { font-size: .82rem; color: var(--text-sub); display: flex; align-items: flex-start; gap: 5px; }
.place-address::before { content: '📍'; font-size: .8rem; flex-shrink: 0; margin-top: 1px; }
.place-phone { font-size: .82rem; color: var(--text-sub); display: flex; align-items: center; gap: 5px; }
.place-phone::before { content: '📞'; font-size: .8rem; }
.place-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--primary); font-size: .82rem; font-weight: 600;
  text-decoration: none; margin-top: 4px;
}
.place-link:hover { text-decoration: underline; }

/* ── Empty ───────────────────────────────────────── */
.empty-box {
  text-align: center; padding: 48px 20px;
  background: var(--white); border-radius: var(--radius);
  border: 1px solid var(--border); grid-column: 1 / -1;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-msg { font-size: .95rem; color: var(--text-sub); }

/* ── Error ───────────────────────────────────────── */
.error-wrap { text-align: center; padding: 48px 20px; }
.error-box {
  display: inline-flex; flex-direction: column; align-items: center; gap: 12px;
  background: var(--white); border-radius: var(--radius);
  padding: 36px 40px; box-shadow: var(--shadow);
}
.error-icon { font-size: 2.4rem; }
.error-msg { font-size: .9rem; color: var(--red); font-weight: 500; max-width: 400px; text-align: center; line-height: 1.5; }
.btn-retry {
  background: var(--primary); color: white; border: none;
  border-radius: var(--radius-sm); padding: 10px 24px;
  font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn-retry:hover { background: var(--primary-dark); }

/* ── Footer ─────────────────────────────────────── */
.site-footer {
  text-align: center; padding: 18px 20px;
  font-size: .8rem; color: var(--text-sub);
  border-top: 1px solid var(--border); background: var(--white);
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 640px) {
  .type-grid { grid-template-columns: 1fr 1fr; }
  .result-grid { grid-template-columns: 1fr; }
  .search-actions { flex-direction: column-reverse; gap: 10px; }
  .btn-search, .btn-back { width: 100%; justify-content: center; }
  .result-header { flex-direction: column; gap: 10px; }
}
@media (max-width: 380px) {
  .type-grid { grid-template-columns: 1fr; }
}
