/* ─── Design Tokens ──────────────────────────────────────────────────── */
:root {
  --orange:        oklch(65% 0.19 42);
  --orange-dim:    oklch(72% 0.16 42);
  --orange-light:  oklch(94% 0.05 50);
  --orange-xlight: oklch(97.5% 0.02 50);
  --green:         oklch(56% 0.16 148);
  --green-light:   oklch(93% 0.07 148);
  --bg:            oklch(98.5% 0.006 50);
  --surface:       oklch(100% 0 0);
  --border:        oklch(91% 0.012 50);
  --border-strong: oklch(84% 0.018 50);
  --text:          oklch(20% 0.018 40);
  --text-mid:      oklch(50% 0.012 40);
  --text-light:    oklch(70% 0.008 40);

  --sp-1: 4px;  --sp-2: 8px;   --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px;  --sp-6: 24px;
  --sp-8: 32px; --sp-12: 48px;

  --r-sm: 10px; --r-md: 16px; --r-lg: 22px; --r-full: 999px;
  --shadow-sm: 0 1px 3px oklch(20% 0.01 40 / 0.08), 0 1px 2px oklch(20% 0.01 40 / 0.06);
  --shadow-md: 0 4px 12px oklch(20% 0.01 40 / 0.10), 0 2px 4px oklch(20% 0.01 40 / 0.06);

  --font-brand: 'Nunito', system-ui, sans-serif;
  --font-body: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input { font-family: inherit; }

/* ─── Header ─────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  background: var(--surface);
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.brand-mark {
  font-family: var(--font-brand);
  font-weight: 900;
  font-size: 1.5rem;
  color: var(--orange);
  letter-spacing: -0.5px;
  line-height: 1;
}
.brand-tag {
  font-size: 0.7rem;
  color: var(--text-light);
  letter-spacing: 0.01em;
}
.location-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-mid);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 6px 12px;
  transition: color 0.15s;
}
.location-btn:hover { color: var(--orange); }

/* ─── Search ─────────────────────────────────────────────────────────── */
.search-wrap {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-light);
  flex-shrink: 0;
  pointer-events: none;
}
#goodsInput {
  width: 100%;
  padding: 11px 36px 11px 38px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#goodsInput:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px oklch(65% 0.19 42 / 0.12);
}
#goodsInput::placeholder { color: var(--text-light); }
.search-clear {
  position: absolute;
  right: 10px;
  width: 22px; height: 22px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  color: var(--text-mid);
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.search-clear.visible { opacity: 1; pointer-events: auto; }

.ai-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 16px;
  background: var(--orange);
  color: white;
  border-radius: var(--r-md);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 8px oklch(65% 0.19 42 / 0.35);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.ai-btn:active { transform: scale(0.96); }
.ai-btn:hover { background: var(--orange-dim); }
.ai-btn.loading { background: var(--orange-dim); pointer-events: none; }
.ai-btn-icon {
  font-size: 1rem;
  line-height: 1;
}

/* ─── Categories ─────────────────────────────────────────────────────── */
.category-scroll {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
.category-scroll::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  padding: 7px 13px;
  border-radius: var(--r-full);
  background: var(--bg);
  border: 1.5px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-mid);
  transition: all 0.15s;
  white-space: nowrap;
}
.cat-chip:hover { border-color: var(--orange); color: var(--orange); }
.cat-chip.active {
  background: var(--orange-light);
  border-color: var(--orange);
  color: var(--orange);
}

/* ─── AI Panel ───────────────────────────────────────────────────────── */
.ai-panel {
  margin: var(--sp-4);
  border-radius: var(--r-lg);
  overflow: hidden;
  min-height: 56px;
}
.ai-thinking {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--orange-xlight);
  border: 1.5px solid var(--orange-light);
  border-radius: var(--r-lg);
  font-size: 0.85rem;
  color: var(--text-mid);
  opacity: 0;
  transition: opacity 0.2s;
}
.ai-thinking.active { opacity: 1; }

.ai-dots { display: flex; gap: 4px; align-items: center; }
.ai-dots span {
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: var(--orange);
  animation: dot-bounce 1.2s infinite;
}
.ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.ai-result {
  display: none;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--orange-xlight);
  border: 1.5px solid var(--orange-light);
  border-radius: var(--r-lg);
  animation: slide-up 0.3s ease-out;
}
.ai-result.active { display: flex; }
.ai-icon {
  font-size: 1.1rem;
  color: var(--orange);
  flex-shrink: 0;
  margin-top: 1px;
}
#aiTips {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
}

/* ─── Results Header ─────────────────────────────────────────────────── */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--sp-4) var(--sp-2);
  font-size: 0.82rem;
  color: var(--text-mid);
  opacity: 0;
  transition: opacity 0.3s;
}
.results-header.visible { opacity: 1; }
.results-header strong { color: var(--text); }
.sort-label { color: var(--text-light); }

/* ─── Store List ─────────────────────────────────────────────────────── */
.store-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
}

/* Skeleton */
.skeleton-card {
  height: 110px;
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Store Card */
.store-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1.5px solid var(--border);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
  animation: card-in 0.35s ease-out backwards;
}
.store-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.store-card:nth-child(1) { animation-delay: 0s; }
.store-card:nth-child(2) { animation-delay: 0.07s; }
.store-card:nth-child(3) { animation-delay: 0.14s; }
.store-card:nth-child(4) { animation-delay: 0.21s; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Winner card */
.store-card.winner {
  border-color: var(--orange);
  background: var(--surface);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-3);
}
.store-name-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.store-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}
.winner-badge {
  display: none;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--orange);
  color: white;
  border-radius: var(--r-full);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.winner .winner-badge { display: flex; }

.price-block {
  text-align: right;
}
.price-main {
  display: flex;
  align-items: baseline;
  gap: 2px;
  justify-content: flex-end;
}
.price-unit { font-size: 0.85rem; font-weight: 700; color: var(--orange); }
.price-num  { font-family: var(--font-brand); font-size: 1.75rem; font-weight: 900; color: var(--orange); line-height: 1; }
.price-per  { font-size: 0.72rem; color: var(--text-light); }
.price-orig {
  font-size: 0.75rem;
  color: var(--text-light);
  text-decoration: line-through;
  text-align: right;
}
.savings-chip {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 7px;
  background: var(--green-light);
  color: var(--green);
  border-radius: var(--r-full);
  font-size: 0.7rem;
  font-weight: 700;
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.store-tag {
  font-size: 0.78rem;
  color: var(--text-mid);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: var(--sp-2);
}
.card-actions {
  display: flex;
  gap: var(--sp-2);
}
.act-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-mid);
  transition: all 0.15s;
}
.act-nav:hover { border-color: var(--orange); color: var(--orange); }
.act-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  background: var(--orange);
  border-radius: var(--r-md);
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  transition: background 0.15s;
}
.act-group:hover { background: var(--orange-dim); }

/* ─── Bottom Actions ─────────────────────────────────────────────────── */
.bottom-actions {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 440px;
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  background: oklch(98.5% 0.006 50 / 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 13px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-mid);
  background: var(--surface);
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--orange); color: var(--orange); }
.btn-primary {
  flex: 2;
  padding: 13px;
  background: var(--orange);
  border-radius: var(--r-md);
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  box-shadow: 0 3px 10px oklch(65% 0.19 42 / 0.3);
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { background: var(--orange-dim); }
.btn-primary:active { transform: scale(0.98); }

/* ─── Slide up anim ──────────────────────────────────────────────────── */
@keyframes slide-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Empty / Error ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-8);
  color: var(--text-light);
  font-size: 0.88rem;
  line-height: 1.8;
}
.empty-state svg { display: block; margin: 0 auto var(--sp-4); opacity: 0.35; }
