:root {
  --bg: #ffffff;
  --surface: #f6f8f6;
  --border: #e7ece8;
  --ink: #16261f;
  --soft: #6b7a72;
  --primary: #1f7a4d;
  --primary-dark: #175e3b;
  --primary-soft: #e8f5ec;
  --accent: #ff5a36;
  --accent-soft: #ffece6;
  --shadow-sm: 0 1px 3px rgba(22, 38, 31, 0.06), 0 1px 2px rgba(22, 38, 31, 0.04);
  --shadow-md: 0 10px 30px rgba(22, 38, 31, 0.12);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100dvh; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
body.locked { overflow: hidden; }
button, input { font: inherit; }
button { border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { border: 0; outline: 0; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

#app {
  width: 100%;
  max-width: 560px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.app-header.scrolled { border-bottom-color: var(--border); box-shadow: var(--shadow-sm); }

.location-btn { max-width: 78%; min-width: 0; padding: 5px 3px; display: flex; align-items: center; gap: 7px; border-radius: 12px; text-align: left; }
.location-btn:active { background: var(--surface); }
.location-pin { width: 35px; height: 35px; flex: none; display: grid; place-items: center; border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.location-pin svg { width: 17px; height: 17px; }
.location-text { min-width: 0; }
.location-label { display: block; color: var(--soft); font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.location-address { min-width: 0; margin-top: 2px; display: flex; align-items: center; gap: 4px; color: var(--ink); font-size: 14.5px; font-weight: 800; white-space: nowrap; }
.location-address > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.location-address .chevron { width: 13px; height: 13px; flex: none; stroke-width: 2.5; }

.cart-btn { position: relative; width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; transition: transform .2s var(--ease); }
.cart-btn:active { transform: scale(.93); }
.cart-btn > svg { width: 20px; height: 20px; }
.cart-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; display: none; place-items: center; border: 2px solid #fff; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; }
.cart-badge.show { display: grid; }

.search-wrap { padding: 2px 16px 10px; }
.search-bar { height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); transition: border-color .2s var(--ease), background .2s var(--ease); }
.search-bar:focus-within { border-color: var(--primary); background: #fff; }
.search-bar > svg { width: 17px; height: 17px; flex: none; color: var(--soft); }
.search-bar input { width: 100%; min-width: 0; background: transparent; color: var(--ink); font-size: 14px; -webkit-user-select: text; user-select: text; }
.search-clear { width: 23px; height: 23px; flex: none; display: none; place-items: center; border-radius: 50%; background: var(--border); color: var(--soft); font-size: 18px; line-height: 1; }
.search-clear.show { display: grid; }

.category-nav { padding: 6px 16px 14px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.category-nav::-webkit-scrollbar { display: none; }
.chip { padding: 9px 16px; flex: none; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--soft); font-size: 13.5px; font-weight: 650; white-space: nowrap; }
.chip.active { border-color: var(--primary); background: var(--primary); color: #fff; }

.app-main { flex: 1; min-height: 0; padding: 4px 16px 96px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.view { animation: view-in .2s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-title { margin: 8px 2px 12px; font-size: 17px; font-weight: 800; }
.store-list, .product-list { display: flex; flex-direction: column; gap: 13px; }

.store-card, .product-card { width: 100%; padding: 13px; display: flex; gap: 13px; border: 1px solid var(--border); border-radius: 20px; background: #fff; box-shadow: var(--shadow-sm); text-align: left; }
.store-card:active { transform: scale(.985); }
.store-thumb { width: 76px; height: 76px; flex: none; display: grid; place-items: center; border-radius: 18px; background: var(--primary-soft); font-size: 34px; }
.store-info, .product-info { flex: 1; min-width: 0; }
.store-name, .product-name { font-size: 15px; font-weight: 800; }
.store-desc { margin-top: 4px; overflow: hidden; color: var(--soft); font-size: 12.5px; white-space: nowrap; text-overflow: ellipsis; }
.store-meta { margin-top: 9px; display: flex; align-items: center; gap: 9px; }
.store-time, .product-store-tag { padding: 3px 8px; display: inline-block; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 11.5px; font-weight: 750; }
.store-rating { font-size: 12px; font-weight: 750; }

.empty-state { padding: 64px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--soft); text-align: center; }
.empty-state .emoji { font-size: 39px; }
.empty-state .title { color: var(--ink); font-size: 16px; font-weight: 800; }
.empty-state .sub { max-width: 280px; font-size: 13px; line-height: 1.45; }

.store-banner { padding: 6px 2px 16px; display: flex; align-items: center; gap: 12px; }
.round-back { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); }
.round-back svg { width: 17px; height: 17px; stroke-width: 2.4; }
.banner-icon { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border-radius: 16px; background: var(--primary-soft); font-size: 23px; }
.banner-name { font-size: 16px; font-weight: 800; }
.banner-meta { margin-top: 3px; color: var(--soft); font-size: 12px; font-weight: 650; }

.product-thumb { width: 64px; height: 64px; flex: none; display: grid; place-items: center; border-radius: 13px; background: var(--surface); font-size: 30px; }
.product-unit { margin-top: 3px; color: var(--soft); font-size: 12px; }
.product-price { margin-top: 4px; font-size: 15px; font-weight: 800; }
.strike { margin-left: 6px; color: var(--soft); font-size: 12px; font-weight: 500; text-decoration: line-through; }
.product-store-tag { margin-top: 5px; }
.product-actions { flex: none; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 8px; }
.stepper { height: 32px; display: flex; align-items: center; overflow: hidden; border: 1.5px solid var(--primary); border-radius: 999px; }
.stepper button { width: 30px; height: 100%; color: var(--primary); font-size: 17px; font-weight: 800; }
.stepper .qty { min-width: 22px; text-align: center; font-size: 13px; font-weight: 800; }
.action-row { display: flex; gap: 6px; }
.action-btn { height: 32px; padding: 0 13px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.add-btn { background: var(--primary-soft); color: var(--primary); }
.buy-btn { background: var(--accent); color: #fff; }

.bottom-nav { position: sticky; bottom: 0; z-index: 30; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: flex; border-top: 1px solid var(--border); background: #fff; box-shadow: 0 -4px 16px rgba(22, 38, 31, .05); }
.nav-item { flex: 1; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 3px; border-radius: 12px; color: var(--soft); }
.nav-item svg { width: 21px; height: 21px; }
.nav-item.active { color: var(--primary); }
.nav-label { font-size: 10.5px; font-weight: 750; }
.nav-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--primary); opacity: 0; }
.nav-item.active .nav-dot { opacity: 1; }

.profile-card { margin: 8px 0 20px; padding: 16px; display: flex; align-items: center; gap: 14px; border-radius: 20px; background: var(--primary-soft); }
.profile-avatar { width: 52px; height: 52px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #fff; font-size: 26px; }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-size: 15.5px; font-weight: 800; }
.profile-phone { margin-top: 3px; color: var(--soft); font-size: 12px; }
.profile-edit { padding: 8px 14px; border-radius: 999px; background: #fff; color: var(--primary); font-size: 12px; font-weight: 750; }
.profile-menu { margin-bottom: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: 20px; }
.profile-menu-item { width: 100%; padding: 14px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); text-align: left; }
.profile-menu-item:last-child { border-bottom: 0; }
.profile-menu-label { flex: 1; font-size: 14px; font-weight: 650; }
.profile-logout { width: 100%; height: 46px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 750; }

.toast { position: fixed; left: 50%; bottom: 92px; z-index: 500; max-width: 88%; padding: 11px 18px; overflow: hidden; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 650; white-space: nowrap; text-overflow: ellipsis; opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity .2s var(--ease), transform .2s var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.cart-overlay { position: fixed; inset: 0; z-index: 60; width: 100%; max-width: 560px; margin: auto; display: flex; flex-direction: column; background: #fff; transform: translateX(calc(50vw + 50%)); transition: transform .26s var(--ease); }
.cart-overlay.open { transform: none; }
.overlay-header { padding: 14px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.overlay-header h2 { font-size: 17px; font-weight: 800; }
.cart-body { flex: 1; min-height: 0; padding: 14px 16px 24px; overflow-y: auto; }
.cart-footer { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.cart-total { margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; color: var(--soft); font-size: 14px; font-weight: 700; }
.cart-total strong { color: var(--ink); font-size: 18px; font-weight: 800; }
.checkout-btn { width: 100%; height: 48px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 15px; font-weight: 800; }

.sheet { position: fixed; inset: 0; z-index: 300; display: none; align-items: flex-end; justify-content: center; background: rgba(0, 0, 0, .38); backdrop-filter: blur(2px); }
.sheet.show { display: flex; }
.sheet-panel { width: 100%; max-width: 560px; padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); border-radius: 26px 26px 0 0; background: #fff; animation: sheet-in .25s var(--ease); }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 20px; font-weight: 800; }
.sheet-close { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 50%; background: var(--surface); color: var(--ink); font-size: 22px; }
.location-access-btn { width: 100%; height: 50px; margin: 3px 0 14px; border-radius: 15px; background: var(--primary); color: #fff; font-size: 14px; font-weight: 800; box-shadow: 0 8px 18px rgba(31, 122, 77, .22); }
.detected-location { margin: 4px 0 12px; padding: 13px; border: 1px solid #cde8d7; border-radius: 15px; background: var(--primary-soft); }
.detected-location small { display: block; margin-bottom: 4px; color: var(--primary); font-size: 11px; font-weight: 800; }
.detected-location strong { display: block; font-size: 13px; line-height: 1.4; }
.manual-address { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.manual-address p { margin-bottom: 7px; color: #435047; font-size: 12px; font-weight: 800; }
.manual-address input { width: 100%; height: 46px; margin-top: 8px; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--ink); font-size: 13px; -webkit-user-select: text; user-select: text; }
.manual-address input:focus { border-color: var(--primary); }
.save-address-btn { width: 100%; height: 47px; margin-top: 10px; border-radius: 13px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 800; }
.location-status { min-height: 34px; margin-top: 12px; color: var(--soft); font-size: 12px; line-height: 1.45; }

@media (max-width: 390px) {
  .product-card { gap: 10px; padding: 11px; }
  .product-thumb { width: 56px; height: 56px; }
  .action-btn { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
