/* ==========================================================
   STF Market — clean / premium / mobile-first styling
   ========================================================== */

:root{
  --bg: #FAF9F6;
  --surface: #FFFFFF;
  --ink: #1C1C1A;
  --ink-soft: #6B6B63;
  --line: #ECE9E2;
  --accent: #2F4B3C;      /* deep forest green */
  --accent-soft: #E7EDE7;
  --gold: #B08D3F;        /* estimated-price accent */
  --gold-soft: #FBF3E1;
  --danger: #C0453A;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(20,20,15,0.06), 0 1px 2px rgba(20,20,15,0.04);
  --shadow-lift: 0 10px 30px rgba(20,20,15,0.14);
  --maxw: 1180px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Noto Sans SC", "Segoe UI", Arial, sans-serif;
}

*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }
body{
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  padding-bottom: 84px; /* room for floating cart bar */
}
h1,h2,h3{ margin:0; font-weight: 650; letter-spacing: -0.01em; }
button{ font-family: inherit; cursor: pointer; }
input,textarea{ font-family: inherit; font-size: 15px; }
a{ color: inherit; }

.en{ color: var(--ink-soft); font-weight: 500; font-size: 0.78em; margin-left: 6px; }

/* ---------------- Header ---------------- */
.site-header{
  position: sticky; top: 0; z-index: 30;
  background: rgba(250,249,246,0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 10px;
}
.header-row{
  max-width: var(--maxw); margin: 0 auto;
  display:flex; align-items:center; justify-content:space-between;
}
.brand{ display:flex; align-items:center; gap:10px; }
.brand-mark{ font-size: 26px; line-height:1; }
.brand-text{ display:flex; flex-direction:column; line-height:1.15; }
.brand-cn{ font-size: 17px; font-weight: 700; color: var(--accent); }
.brand-en{ font-size: 11px; color: var(--ink-soft); letter-spacing: 0.06em; text-transform: uppercase; }

.icon-btn{
  border:none; background: var(--surface); color: var(--ink);
  width:40px; height:40px; border-radius: 50%;
  display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow); position: relative;
}
.cart-badge{
  position:absolute; top:-4px; right:-4px;
  background: var(--accent); color:#fff; font-size: 11px; font-weight:700;
  min-width:18px; height:18px; border-radius:9px; padding:0 4px;
  display:flex; align-items:center; justify-content:center;
}

.search-row{ max-width: var(--maxw); margin: 10px auto 0; }
.search-box{
  display:flex; align-items:center; gap:8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 14px;
  box-shadow: var(--shadow);
}
.search-box svg{ color: var(--ink-soft); flex: none; }
.search-box input{
  border:none; outline:none; flex:1; background:transparent; font-size: 15px; color: var(--ink);
}
.search-box input::placeholder{ color: #B7B4AA; }
.clear-search{
  border:none; background: var(--line); color: var(--ink-soft);
  width:22px; height:22px; border-radius:50%; font-size: 12px; flex:none;
  align-items:center; justify-content:center;
}

.promo-strip{
  max-width: var(--maxw); margin: 10px auto 0; padding: 7px 4px 0;
  text-align:center; font-size: 12px; letter-spacing: 0.01em;
  color: var(--ink-soft); border-top: 1px solid var(--line);
}
.promo-strip .tag{ color: var(--gold); font-weight: 650; }
.clear-search:not([hidden]){ display:flex; }

/* ---------------- Category nav ---------------- */
.category-nav{
  position: sticky; top: var(--header-h, 108px); z-index: 20;
  display:flex; align-items:center; gap:6px;
  padding: 10px 10px 10px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.cat-scroll{
  flex: 1 1 auto; min-width: 0;
  display:flex; gap:8px; overflow-x:auto; -webkit-overflow-scrolling:touch;
  scrollbar-width:none; scroll-behavior:smooth;
  mask-image: linear-gradient(to right, black calc(100% - 26px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 26px), transparent 100%);
}
.cat-scroll::-webkit-scrollbar{ display:none; }
.cat-chip{
  flex: none; border:1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); padding: 8px 14px; border-radius: 999px;
  font-size: 13.5px; font-weight:600; white-space:nowrap;
  display:flex; align-items:center; gap:6px; transition: all .15s ease;
  scroll-snap-align: start;
}
.cat-chip.active{ background: var(--accent); color:#fff; border-color: var(--accent); }

.cat-all-btn{
  flex: none; width:36px; height:36px; border-radius:50%;
  border:1px solid var(--line); background: var(--surface); color: var(--accent);
  display:flex; align-items:center; justify-content:center; box-shadow: var(--shadow);
  margin-left: 2px;
}

/* On roomy screens, let chips wrap onto multiple rows instead of scrolling,
   and hide the redundant "all categories" shortcut since everything fits. */
@media (min-width: 860px){
  .cat-scroll{ flex-wrap: wrap; overflow-x: visible; mask-image:none; -webkit-mask-image:none; }
  .cat-all-btn{ display:none; }
}

/* ---------------- All-categories quick sheet ---------------- */
.cat-all-sheet{
  position: fixed; left:0; right:0; bottom:0; z-index: 60;
  max-height: 72vh; background: var(--bg);
  border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,0.18);
  animation: slideUp .22s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.cat-all-sheet:not([hidden]){ display:flex; flex-direction:column; }
@keyframes slideUp{ from{ transform: translateY(100%); } to{ transform: translateY(0); } }
.cat-all-grid{
  padding: 14px 18px 24px; overflow-y:auto;
  display:grid; grid-template-columns: repeat(2, 1fr); gap:10px;
}
@media (min-width: 620px){ .cat-all-grid{ grid-template-columns: repeat(3, 1fr); } }
.cat-all-item{
  display:flex; align-items:center; gap:10px; text-align:left;
  border:1px solid var(--line); background: var(--surface); border-radius: var(--radius-md);
  padding: 12px 12px; font-size: 13.5px; font-weight:600; color: var(--ink);
}
.cat-all-item .emoji{ font-size:20px; }
.cat-all-item .cnt{ margin-left:auto; font-size:11.5px; font-weight:600; color: var(--ink-soft); }
.cat-all-item.active{ border-color: var(--accent); background: var(--accent-soft); }

/* ---------------- Main / sections ---------------- */
main{ max-width: var(--maxw); margin: 0 auto; padding: 4px 16px 24px; }
.category-section{ padding-top: 22px; scroll-margin-top: calc(var(--header-h, 108px) + var(--nav-h, 56px) + 10px); }
.section-title{
  font-size: 19px; margin-bottom: 12px; display:flex; align-items:baseline; gap:8px;
}
.section-title .count{ font-size: 13px; color: var(--ink-soft); font-weight:500; }

.product-grid{
  display:grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
@media (min-width: 620px){ .product-grid{ grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px){ .product-grid{ grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px){ .product-grid{ grid-template-columns: repeat(5, 1fr); } }

.product-card{
  background: var(--surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow); overflow:hidden; display:flex; flex-direction:column;
  position:relative; transition: transform .15s ease, box-shadow .15s ease;
}
.product-card:hover{ transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.product-thumb{
  width:100%; aspect-ratio: 1/1; object-fit: cover; background: #F3F1EC; display:block;
}
.product-info{ padding: 10px 10px 12px; display:flex; flex-direction:column; gap:4px; flex:1; }
.product-name-cn{ font-size: 13.5px; font-weight:650; line-height:1.3;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.product-name-en{ font-size: 11px; color: var(--ink-soft);
  display:-webkit-box; -webkit-line-clamp:1; -webkit-box-orient:vertical; overflow:hidden; }
.product-price-row{ display:flex; align-items:center; justify-content:space-between; margin-top:4px; }
.price-tag{ font-size: 15px; font-weight:750; color: var(--accent); }
.price-tag.est{ color: var(--gold); }
.est-badge{
  font-size: 9.5px; font-weight:700; color: var(--gold); background: var(--gold-soft);
  border-radius: 5px; padding: 1px 5px; margin-left:5px; vertical-align: 1px;
}

.qty-stepper{ display:flex; align-items:center; gap:6px; }
.qty-btn{
  width:26px; height:26px; border-radius:50%; border:none; background: var(--accent-soft);
  color: var(--accent); font-size:16px; font-weight:700; display:flex; align-items:center; justify-content:center;
  line-height: 1;
}
.qty-btn.add-first{
  width:30px; height:30px; background: var(--accent); color:#fff; font-size: 18px; border-radius: 9px;
}
.qty-num{ min-width: 16px; text-align:center; font-weight:700; font-size:14px; }

.empty-state{ text-align:center; color: var(--ink-soft); padding: 40px 10px; font-size:14px; line-height:1.8; }

/* ---------------- Footer ---------------- */
.site-footer{ max-width: var(--maxw); margin: 20px auto 0; padding: 18px 16px 40px;
  color: var(--ink-soft); font-size: 12px; border-top: 1px solid var(--line); }
.site-footer p{ margin: 2px 0; }
.site-footer .muted{ opacity: .8; }

/* ---------------- Floating cart bar ---------------- */
.cart-floatbar{
  position: fixed; left:0; right:0; bottom: 0; z-index: 40;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
#cartFloatbarBtn{
  max-width: var(--maxw); margin:0 auto; width:100%;
  display:flex; align-items:center; justify-content:space-between;
  background: var(--accent); color:#fff; border:none; border-radius: 999px;
  padding: 13px 20px; box-shadow: var(--shadow-lift); font-size: 14.5px; font-weight:700;
}
.cfb-count{ display:flex; align-items:center; gap:6px; }
.cfb-count::before{ content:"🛒"; }
.cfb-total{ opacity:.95; }
.cfb-cta{ background: rgba(255,255,255,0.18); padding: 6px 12px; border-radius:999px; }

/* ---------------- Overlay & Drawer ---------------- */
.overlay{
  position: fixed; inset:0; background: rgba(15,15,12,0.45); z-index: 50;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }

.drawer{
  position: fixed; right:0; top:0; bottom:0; z-index: 60;
  width: 100%; max-width: 460px; background: var(--bg);
  box-shadow: -12px 0 40px rgba(0,0,0,0.18);
  flex-direction:column;
  animation: slideIn .22s ease;
}
.drawer:not([hidden]){ display:flex; }
@keyframes slideIn{ from{ transform: translateX(100%); } to{ transform: translateX(0); } }

.drawer-header{
  display:flex; align-items:center; justify-content:space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.drawer-header h2{ font-size: 17px; }
.drawer-body{ padding: 16px 18px 24px; overflow-y:auto; flex:1; }

.cart-item{
  display:flex; gap:10px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.cart-item img{ width:60px; height:60px; border-radius: var(--radius-sm); object-fit:cover; background:#F3F1EC; flex:none; }
.cart-item-info{ flex:1; min-width:0; }
.cart-item-name{ font-size: 13.5px; font-weight:650; line-height:1.3; }
.cart-item-en{ font-size: 10.5px; color: var(--ink-soft); }
.cart-item-row{ display:flex; align-items:center; justify-content:space-between; margin-top:6px; }
.cart-item-remove{ border:none; background:none; color:#B7B4AA; font-size:12px; text-decoration:underline; padding:0; }

.price-summary{
  margin-top: 16px; background: var(--surface); border-radius: var(--radius-md);
  padding: 14px 16px; box-shadow: var(--shadow); font-size: 13.5px;
}
.ps-row{ display:flex; justify-content:space-between; padding: 4px 0; }
.ps-row.total{ font-size: 16px; font-weight:750; border-top: 1px dashed var(--line); margin-top:6px; padding-top:10px; }
.ps-label-note{ display:block; font-size: 11px; color: var(--ink-soft); font-weight:400; margin-top:1px; }
.ps-est{ color: var(--gold); }
.ps-discount{ color: var(--accent); font-weight: 650; }
.ps-discount span:first-child{ padding-right: 10px; }
.ps-hint{ padding: 2px 0; }
.ps-legend{ font-size: 11px; color: var(--ink-soft); margin-top:10px; line-height:1.6; }
.dot{ display:inline-block; width:7px; height:7px; border-radius:50%; margin-right:5px; }
.dot.real{ background: var(--accent); }
.dot.est{ background: var(--gold); }

.back-link{ border:none; background:none; color: var(--ink-soft); font-size:13px; padding:0 0 12px; }
.form-title{ font-size: 17px; margin-bottom: 4px; }
#checkoutForm{ display:flex; flex-direction:column; gap:14px; margin-top: 14px; }
#checkoutForm label{ display:flex; flex-direction:column; gap:6px; font-size: 13px; font-weight:650; color: var(--ink); }
#checkoutForm input, #checkoutForm textarea{
  border:1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
  background: var(--surface); resize: vertical; color: var(--ink);
}
#checkoutForm input:focus, #checkoutForm textarea:focus{ outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.req{ color: var(--danger); }
.opt{ color: var(--ink-soft); font-weight:500; }
.form-hint{ font-size: 11.5px; color: var(--ink-soft); line-height:1.6; margin-top: 2px; }
.turnstile-slot{ display:flex; justify-content:center; min-height:65px; }
.form-error{
  background: #FBEAE8; color: var(--danger); border:1px solid #F1CFC9;
  border-radius: var(--radius-sm); padding: 8px 12px; font-size: 12.5px; line-height:1.5;
}
.form-error:not([hidden]){ display:block; }

.primary-btn{
  width:100%; background: var(--accent); color:#fff; border:none; border-radius: 999px;
  padding: 14px; font-size: 15px; font-weight:700; margin-top: 4px;
  box-shadow: var(--shadow);
}
.primary-btn:disabled{ opacity:.6; }
.secondary-btn{
  width:100%; background: var(--surface); color: var(--accent); border:1px solid var(--accent);
  border-radius: 999px; padding: 13px; font-size: 14px; font-weight:700; margin-top: 14px;
}

.done-icon{ font-size: 46px; text-align:center; margin-top: 10px; }
.done-desc{ text-align:center; color: var(--ink-soft); font-size:13.5px; margin-top:6px; }

.toast{
  position: fixed; bottom: 96px; left:50%; transform:translateX(-50%);
  background: var(--ink); color:#fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 90; box-shadow: var(--shadow-lift);
  animation: toastIn .2s ease;
}
@keyframes toastIn{ from{ opacity:0; transform:translateX(-50%) translateY(8px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }

@media (max-width: 480px){
  .drawer{ max-width: 100%; }
  .brand-en{ display:none; }
}
