:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --surface2: #f4f3ef;
  --border: #e8e6e0;
  --text: #1a1a18;
  --text-muted: #6b6960;
  --accent: #2d5016;
  --accent-light: #4a7c28;
  --accent-bg: #eef4e8;
  --seoul-color: #2563eb;
  --gyeonggi-color: #7c3aed;
  --tag-bg: #f0ede6;
  --tag-text: #4a4640;
  --star: #f59e0b;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --shadow-hover: 0 6px 24px rgba(0,0,0,0.12);
}

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

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── Header ── */
header {
  background: var(--accent);
  color: white;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo span { font-size: 1.4rem; }
#search-input {
  flex: 1;
  max-width: 400px;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  font-size: 0.95rem;
  outline: none;
  background: rgba(255,255,255,0.15);
  color: white;
}
#search-input::placeholder { color: rgba(255,255,255,0.65); }
#search-input:focus { background: rgba(255,255,255,0.25); }

/* ── Hero ── */
#hero {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: white;
  padding: 56px 24px;
  text-align: center;
}
#hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: 10px; }
#hero p { font-size: 1.05rem; opacity: 0.88; }
.hero-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 28px;
}
.stat { text-align: center; }
.stat-num { font-size: 2rem; font-weight: 800; }
.stat-label { font-size: 0.8rem; opacity: 0.8; }

/* ── Filter Bar ── */
#filter-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 60px;
  z-index: 90;
}
.filter-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
.filter-btn {
  padding: 5px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: white;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--accent-light); color: var(--accent); }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.sort-select {
  margin-left: auto;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: white;
  cursor: pointer;
  outline: none;
}

/* ── Main Layout ── */
main { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

/* ── Grid View ── */
#cafe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.cafe-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.cafe-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-light);
}
.card-region {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}
.region-서울 { background: #dbeafe; color: var(--seoul-color); }
.region-경기 { background: #ede9fe; color: var(--gyeonggi-color); }

.card-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.card-district { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 10px; }
.card-summary {
  font-size: 0.88rem;
  color: #4a4640;
  line-height: 1.55;
  margin-bottom: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-rating {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 0.9rem;
}
.card-rating .star { color: var(--star); }
.card-price { font-size: 0.78rem; color: var(--text-muted); }
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}
.tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 12px;
}

/* ── Detail View ── */
#detail-view {
  display: none;
  max-width: 800px;
  margin: 0 auto;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  transition: all 0.15s;
}
.back-btn:hover { background: var(--border); color: var(--text); }

.detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.detail-header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: white;
  padding: 32px 28px;
}
.detail-region {
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 12px;
  display: inline-block;
  margin-bottom: 12px;
}
.detail-name { font-size: 1.8rem; font-weight: 800; margin-bottom: 6px; }
.detail-district { opacity: 0.85; font-size: 0.95rem; }
.detail-rating-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.detail-rating {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 1.1rem;
  font-weight: 700;
}
.detail-rating .star { color: var(--star); font-size: 1.2rem; }

.detail-body { padding: 28px; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--surface2);
  border-radius: 8px;
}
.info-item label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 2px;
}
.info-item span { font-size: 0.9rem; font-weight: 500; }

.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 24px; }
.detail-tag {
  font-size: 0.8rem;
  padding: 4px 12px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 14px;
  font-weight: 600;
}

.detail-content { font-size: 0.95rem; line-height: 1.75; }
.detail-content h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  margin: 20px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent-bg);
}
.detail-content p { margin-bottom: 12px; color: #3a3730; }
.detail-content ul { margin: 8px 0 12px 20px; }
.detail-content li { margin-bottom: 4px; }
.detail-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
  font-size: 0.88rem;
}
.detail-content th, .detail-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.detail-content th {
  background: var(--surface2);
  font-weight: 700;
  color: var(--text-muted);
}

/* ── Empty / Count ── */
#result-count {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
#no-results {
  display: none;
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* ── AI Search ── */
.ai-btn {
  padding: 7px 14px;
  background: rgba(255,255,255,0.18);
  border: 1.5px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai-btn:hover { background: rgba(255,255,255,0.28); }
.ai-btn.active { background: white; color: var(--accent); border-color: white; }

#ai-panel {
  display: none;
  background: var(--surface);
  border-bottom: 2px solid var(--accent-bg);
  padding: 20px 24px;
}
#ai-panel.open { display: block; }
.ai-panel-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
#ai-input {
  flex: 1;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  height: 46px;
  transition: border-color 0.15s;
}
#ai-input:focus { border-color: var(--accent-light); }
#ai-submit {
  padding: 11px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  height: 46px;
}
#ai-submit:hover { background: var(--accent-light); }
#ai-submit:disabled { background: #aaa; cursor: not-allowed; }

#ai-result {
  max-width: 820px;
  margin: 14px auto 0;
  display: none;
}
#ai-result.show { display: block; }
.ai-answer-box {
  background: var(--accent-bg);
  border: 1px solid #c8ddb8;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 0.92rem;
  line-height: 1.7;
  color: #2a3d1a;
  white-space: pre-wrap;
}
.ai-answer-box.error {
  background: #fff0f0;
  border-color: #f5c6cb;
  color: #721c24;
}
.ai-cafe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.ai-cafe-chip {
  padding: 5px 13px;
  background: var(--accent);
  color: white;
  border-radius: 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.ai-cafe-chip:hover { background: var(--accent-light); }

.cafe-card.ai-highlight {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(74,124,40,0.18);
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--accent);
  color: white;
  padding: 2px 7px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: middle;
}

.ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 10px 0;
}
.ai-spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 600px) {
  #hero h1 { font-size: 1.5rem; }
  .hero-stats { gap: 20px; }
  .stat-num { font-size: 1.5rem; }
  #cafe-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .header-inner { gap: 8px; }
  .logo { font-size: 1rem; }
  #search-input { font-size: 0.85rem; }
}
