/* Layout: a maker's shelf — shop sign on top, square product tiles in a wrapping grid, detail opens as a sheet */
:root {
  --bg: #f5f4f1; --surface: #ffffff; --ink: #24211e; --muted: #6b655e; --line: #e2ded7;
  --accent: #2f4a7a; --accent-ink: #ffffff; --accent-soft: #e6ebf3;
  --price: #8a5a12; --sold: #8c8680; --danger: #a23b2c; --shade: rgba(24, 22, 20, .55);
  --line-green: #06c755;
  --display: "Mitr", "Anuphan", system-ui, sans-serif;
  --body: "Anuphan", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --surface: #201e1c; --ink: #ece8e2; --muted: #a59e95; --line: #34302c;
    --accent: #8fa8d6; --accent-ink: #111826; --accent-soft: #232b3a;
    --price: #e0b064; --sold: #8c8680; --danger: #e48a7b; --shade: rgba(0, 0, 0, .65);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.6; }
img { max-width: 100%; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

.wrap {
  max-width: 1160px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- shop sign ---------- */
.shop { border-bottom: 1px solid var(--line); background: var(--surface); }
.shop-in { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding-block: 28px 24px; }
.brand { min-width: 0; display: flex; align-items: center; gap: 16px; }
.brand-text { min-width: 0; }
.logo { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; background: var(--line); border: 1px solid var(--line); }
h1 { font-family: var(--display); font-weight: 500; font-size: clamp(28px, 5vw, 42px); line-height: 1.15; margin: 0; text-wrap: balance; }
.tagline { margin: 4px 0 0; color: var(--muted); }
.contact { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 16px; border-radius: 999px; font-weight: 500; font-size: 15px; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.line { background: var(--line-green); border-color: var(--line-green); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger.solid { background: var(--danger); color: var(--surface); }
.btn.big { padding: 12px 20px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- admin bar ---------- */
.adminbar { background: var(--accent-soft); border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; }
.adminbar-in { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding-block: 10px; }
.admin-label { font-weight: 600; color: var(--accent); font-size: 14px; }

/* ---------- tools ---------- */
.tools { display: flex; flex-direction: column; gap: 12px; padding-block: 24px 4px; }
.search { width: 100%; max-width: 420px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 10px 18px; font: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); padding: 5px 14px; border-radius: 999px; font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.count { color: var(--muted); font-size: 14px; margin: 12px 0; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin-top: 12px; font-size: 15px; }

/* ---------- product grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 24px 18px; padding-bottom: 32px; }
.card { display: flex; flex-direction: column; gap: 10px; text-align: left; background: none; border: 0; padding: 0; color: inherit; min-width: 0; }
.cover { position: relative; aspect-ratio: 1; max-width: 100%; width: 100%; border-radius: 12px; overflow: hidden; background: var(--line); display: grid; place-items: center; }
.cover img, .cover video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%; background: var(--shade); color: #fff; display: grid; place-items: center; font-size: 16px; padding-left: 3px; pointer-events: none; }
.strip .play, .thumb .play { width: 26px; height: 26px; font-size: 11px; }
.card:hover .cover img { transform: scale(1.04); }
.cover .ph { font-family: var(--display); font-size: 48px; color: var(--muted); }
.cover .more { position: absolute; right: 8px; bottom: 8px; background: var(--shade); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.soldtag { position: absolute; left: 10px; top: 10px; background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.card.sold .cover img { filter: grayscale(.7); opacity: .7; }
.meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-inline: 2px; }
.cat { font-size: 13px; color: var(--muted); }
.ttl { font-weight: 600; font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.price { font-family: var(--display); color: var(--price); font-size: 18px; font-variant-numeric: tabular-nums; }
.card.sold .price { color: var(--sold); text-decoration: line-through; }

.empty { border: 1.5px dashed var(--line); border-radius: 12px; padding: 56px 20px; text-align: center; color: var(--muted); margin-bottom: 32px; }
.empty h2 { font-family: var(--display); font-weight: 500; color: var(--ink); font-size: 24px; margin: 0 0 6px; }
.empty p { margin: 0 auto 18px; max-width: 46ch; }

.foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 14px; }
.foot-in { display: flex; flex-direction: column; gap: 20px; padding-block: 28px 40px; }
.foot-contact h2 { font-family: var(--display); font-weight: 500; font-size: 20px; color: var(--ink); margin: 0 0 10px; }
.foot-bottom { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }
.contact.center { justify-content: center; }

/* ---------- sheets ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--shade); z-index: 30; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto;
  padding-top: calc(24px + env(safe-area-inset-top, 0px)); padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.sheet { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.sheet.wide { max-width: 960px; }
.sheet.narrow { max-width: 420px; }
.sheet h2 { font-family: var(--display); font-weight: 500; font-size: 24px; margin: 0; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.x-close { flex: 0 0 auto; width: 40px; height: 40px; margin: -8px -8px 0 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 0; }
.x-close:hover { background: var(--bg); color: var(--ink); }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > label { flex: 1 1 200px; min-width: 0; }
label, .lbl { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 500; }
.lbl { margin-bottom: 6px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { margin: -8px 0 0; font-size: 13px; color: var(--muted); }
input[type=text], input[type=number], input[type=tel], input[type=password], textarea {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 16px; width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
.pw { position: relative; display: block; }
.pw input { padding-right: 48px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 0; }
.eye:hover { color: var(--accent); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; max-width: 100%; border-radius: 8px; overflow: hidden; background: var(--line); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--shade); color: #fff; font-size: 15px; line-height: 1; }
.thumb .first { position: absolute; left: 4px; bottom: 4px; background: var(--accent); color: var(--accent-ink); font-size: 11px; padding: 0 6px; border-radius: 4px; }
.thumb .mv { position: absolute; left: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--shade); color: #fff; font-size: 13px; line-height: 1; }
.pick { aspect-ratio: 1; border: 1.5px dashed var(--line); border-radius: 8px; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px; }
.pick input { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.actions .spacer { flex: 1; }
.actions.start { justify-content: flex-start; }
.btn.small { padding: 5px 12px; font-size: 14px; }
select { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 8px; padding: 9px 10px; font: inherit; font-size: 15px; width: 100%; }
.user-ctl select { width: auto; padding: 5px 8px; font-size: 14px; }

/* shop settings: logo */
.logo-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.logo-preview { width: 88px; height: 88px; border-radius: 50%; overflow: hidden; background: var(--bg); border: 1.5px dashed var(--line); display: grid; place-items: center; text-align: center; font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.logo-preview img { width: 100%; height: 100%; object-fit: cover; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.logo-actions .hint { margin: 0; }

/* users */
.users { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; }
.user { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.user + .user { border-top: 1px solid var(--line); }
.user-main { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.user-name { min-width: 0; overflow-wrap: anywhere; }
.user-ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.user-sub { display: flex; flex-direction: column; gap: 8px; }
.user-sub.confirm { flex-direction: row; }
.muted { color: var(--muted); font-size: 14px; }
.you { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 999px; }
.adduser { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 16px; }
.adduser h3 { margin: 0; font-family: var(--display); font-weight: 500; font-size: 18px; }
.status { font-size: 13px; color: var(--muted); }
.err { color: var(--danger); font-size: 14px; margin: 0; }

/* product detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; }
.gallery { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.slider { position: relative; background: var(--line); border-radius: 12px; overflow: hidden; aspect-ratio: 1; max-width: 100%; touch-action: pan-y; }
.slide-media { width: 100%; height: 100%; }
.slider img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slider video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--shade); color: #fff; font-size: 22px; line-height: 1; display: grid; place-items: center; padding: 0; }
.arrow.prev { left: 8px; } .arrow.next { right: 8px; }
.strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.strip button { flex: 0 0 60px; height: 60px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--line); }
.strip button[aria-current="true"] { border-color: var(--accent); }
.strip button { position: relative; }
.strip img, .strip video { width: 100%; height: 100%; object-fit: cover; display: block; }
.info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.info .price { font-size: 26px; }
.stock { align-self: flex-start; font-size: 14px; font-weight: 600; padding: 2px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.stock.out { background: var(--line); color: var(--muted); }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; color: var(--ink); }
.order { display: flex; flex-direction: column; gap: 8px; }
.order .btn { width: 100%; }
.adminrow { border-top: 1px solid var(--line); padding-top: 14px; }
.confirm { background: var(--bg); border-radius: 10px; padding: 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.confirm span { flex: 1 1 200px; }


.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px; z-index: 40; max-width: calc(100% - 32px); text-align: center; }

@media (max-width: 720px) {
  .detail { grid-template-columns: 1fr; gap: 18px; }
  .sheet { padding: 18px; }
}
@media (max-width: 480px) {
  .logo { width: 56px; height: 56px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; }
  .ttl { font-size: 15px; }
  .price { font-size: 16px; }
  .contact .btn { padding: 7px 12px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .cover img { transition: none; } .card:hover .cover img { transform: none; } }
