/* UNIQLO Mini App Shop — mobile-first, self-contained (no external CSS framework) */

:root {
  /* Fixed, always-readable palette. We deliberately do NOT inherit
     --tg-theme-* for text/bg, because an unexpected theme (e.g. white-on-white)
     can make the whole catalog invisible. UNIQLO brand look is light anyway. */
  --bg:        #ffffff;
  --fg:        #1c1c1e;
  --muted:     #8e8e93;
  --card:      #f2f2f7;
  --accent:    #e60012;   /* UNIQLO red */
  --accent-fg: #ffffff;
  --border:    rgba(0,0,0,0.08);
  --sale:      #e60012;
  --topbar-h:  48px;
  --tabs-h:    44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The hidden attribute must always win over component display rules
   (e.g. .cart-overlay{display:flex}) — otherwise hidden overlays stay visible. */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Khmer OS", sans-serif;
  font-size: 15px; line-height: 1.4;
}
img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
}
#title { font-weight: 700; font-size: 17px; letter-spacing: 0.5px; }
.icon-btn {
  border: none; background: transparent; color: var(--fg);
  font-size: 22px; line-height: 1; padding: 6px 8px; position: relative;
  border-radius: 8px;
}
.icon-btn:active { background: var(--card); }
.badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--accent); color: var(--accent-fg);
  font-size: 11px; font-weight: 700; min-width: 17px; height: 17px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* ---------- Tabs ---------- */
#tabs {
  height: var(--tabs-h);
  display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 999px; padding: 6px 16px; white-space: nowrap; font-size: 14px;
}
.tab.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }

/* ---------- Grid ---------- */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  padding: 2px;
}
@media (min-width: 560px) { .grid { grid-template-columns: 1fr 1fr 1fr; } }
@media (min-width: 820px) { .grid { grid-template-columns: 1fr 1fr 1fr 1fr; } }

.card { background: var(--card); position: relative; overflow: hidden; }
.card .thumb { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--card); }
.card .info { padding: 8px 8px 12px; }
.card .name {
  font-size: 13px; font-weight: 500; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.5em;
}
.card .price { font-size: 14px; font-weight: 700; }
.card .price .orig { color: var(--muted); font-weight: 400; text-decoration: line-through; margin-left: 6px; font-size: 12px; }
.card .colors { color: var(--muted); font-size: 11px; margin-top: 3px; }
.tag-sale {
  position: absolute; top: 8px; left: 8px;
  background: var(--sale); color: #fff; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
}

/* ---------- Detail ---------- */
#detailView { padding-bottom: 90px; }
.detail-gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.detail-gallery::-webkit-scrollbar { display: none; }
.detail-gallery img { width: 100%; flex: 0 0 100%; aspect-ratio: 3/4; object-fit: cover; scroll-snap-align: center; }
.detail-body { padding: 16px; }
.detail-name { font-size: 18px; font-weight: 600; margin: 0 0 6px; }
.detail-price { font-size: 22px; font-weight: 800; color: var(--accent); }
.detail-price .orig { color: var(--muted); font-weight: 400; text-decoration: line-through; font-size: 15px; margin-left: 8px; }
.section-label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.5px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  border: 2px solid var(--border); border-radius: 10px; padding: 4px; background: var(--bg);
  width: 56px; text-align: center;
}
.swatch.active { border-color: var(--accent); }
.swatch img { width: 46px; height: 60px; object-fit: cover; border-radius: 6px; }
.swatch span { font-size: 9px; color: var(--muted); display: block; margin-top: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.sizes { display: flex; gap: 8px; flex-wrap: wrap; }
.size-pill {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 8px; padding: 8px 14px; min-width: 44px; text-align: center; font-size: 14px;
}
.size-pill.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }

.detail-link { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 13px; text-decoration: underline; }

/* ---------- Sticky add-to-cart ---------- */
.add-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; align-items: center;
}
.add-btn {
  flex: 1; background: var(--accent); color: var(--accent-fg);
  border: none; border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 700;
}
.add-btn:disabled { opacity: 0.45; }
.add-btn:active:not(:disabled) { filter: brightness(0.92); }

/* ---------- Cart ---------- */
.cart-overlay {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: flex; flex-direction: column;
}
.cart-head { display:flex; align-items:center; justify-content:space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cart-head h2 { margin: 0; font-size: 17px; }
.cart-items { flex: 1; overflow-y: auto; padding: 8px 16px; }
.cart-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cart-item img { width: 60px; height: 80px; object-fit: cover; border-radius: 8px; }
.cart-item .ci-body { flex: 1; }
.cart-item .ci-name { font-weight: 500; font-size: 14px; }
.cart-item .ci-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cart-item .ci-price { font-weight: 700; }
.ci-remove { color: var(--muted); background: none; border: none; font-size: 13px; text-decoration: underline; padding: 4px 0; }
.cart-foot { border-top: 1px solid var(--border); padding: 16px; }
.cart-total { display:flex; justify-content: space-between; font-size: 17px; font-weight: 800; margin-bottom: 12px; }
.checkout-btn { width: 100%; background: var(--accent); color: var(--accent-fg); border: none; border-radius: 12px; padding: 15px; font-size: 16px; font-weight: 700; }
.cart-empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
#footer { text-align: center; color: var(--muted); font-size: 11px; padding: 20px 0 40px; }
.qty-row { display: flex; align-items: center; gap: 12px; }
.qty-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); font-size: 18px; }
