/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
:root{
  --bg:#f6f7f9;
  --card:#ffffff;
  --ink:#16181d;
  --ink-2:#5c6472;
  --line:#e4e7ec;
  --accent:#c8102e;
  --accent-soft:#fdecef;
  --dark:#1d2129;
  --ok:#0a7d4b;
  --radius:14px;
  --shadow:0 1px 2px rgba(16,24,40,.05), 0 8px 24px -12px rgba(16,24,40,.18);
  --shadow-lg:0 24px 60px -20px rgba(16,24,40,.35);
}
html,body{ margin:0; padding:0; }
body{
  font-family:"Noto Sans Thai","Sarabun","Segoe UI",system-ui,-apple-system,sans-serif;
  background:var(--bg); color:var(--ink);
  -webkit-font-smoothing:antialiased;
}
img{ max-width:100%; display:block; }
button{ font:inherit; cursor:pointer; }
[hidden]{ display:none !important; }
.ico{ width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; flex:none; }

/* ============ Topbar ============ */
.topbar{
  position:sticky; top:0; z-index:40;
  background:rgba(255,255,255,.92); backdrop-filter:blur(12px);
  border-bottom:1px solid var(--line);
}
.topbar-inner{
  max-width:1360px; margin:0 auto; padding:12px 20px;
  display:flex; align-items:center; gap:18px;
}
.brand{ display:flex; align-items:center; gap:11px; flex:none; }
.brand-mark{
  width:42px; height:42px; border-radius:11px; flex:none;
  background:linear-gradient(140deg,var(--accent),#8d0a20);
  color:#fff; font-weight:800; letter-spacing:.5px;
  display:grid; place-items:center; font-size:15px;
}
.brand-text{ display:flex; flex-direction:column; line-height:1.25; }
.brand-text strong{ font-size:15px; }
.brand-text span{ font-size:11.5px; color:var(--ink-2); }

.search-wrap{
  flex:1; position:relative; display:flex; align-items:center;
  background:#fff; border:1px solid var(--line); border-radius:11px;
  padding:0 12px; height:42px; max-width:520px; margin:0 auto;
  transition:border-color .15s, box-shadow .15s;
}
.search-wrap:focus-within{ border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.search-wrap .ico{ color:var(--ink-2); }
#search{ border:0; outline:0; flex:1; height:100%; padding:0 8px; font-size:14px; background:transparent; }
.search-clear{ border:0; background:#eef0f3; color:var(--ink-2); width:22px; height:22px; border-radius:50%; line-height:1; font-size:16px; }

.cart-btn{
  position:relative; flex:none; display:flex; align-items:center; gap:8px;
  background:var(--dark); color:#fff; border:0; border-radius:11px;
  padding:0 16px; height:42px; font-size:14px; font-weight:600;
  transition:transform .12s, background .15s;
}
.cart-btn:hover{ background:#000; }
.cart-btn:active{ transform:scale(.97); }
.badge{
  font-style:normal; min-width:20px; height:20px; padding:0 5px;
  background:var(--accent); border-radius:10px;
  font-size:11.5px; font-weight:700; display:grid; place-items:center;
}

/* categories */
.cats{
  max-width:1360px; margin:0 auto; padding:0 20px 11px;
  display:flex; gap:8px; overflow-x:auto; scrollbar-width:thin;
}
.cats::-webkit-scrollbar{ height:4px; }
.cats::-webkit-scrollbar-thumb{ background:#d2d6dd; border-radius:4px; }
.cat{
  flex:none; border:1px solid var(--line); background:#fff; color:var(--ink-2);
  border-radius:999px; padding:7px 15px; font-size:13px; font-weight:600;
  display:flex; align-items:center; gap:6px; white-space:nowrap;
  transition:.15s;
}
.cat:hover{ border-color:#c9ced7; color:var(--ink); }
.cat.on{ background:var(--dark); border-color:var(--dark); color:#fff; }
.cat em{ font-style:normal; opacity:.65; font-size:11.5px; }

/* ============ Layout ============ */
.wrap{ max-width:1360px; margin:0 auto; padding:22px 20px 60px; }
.results-bar{
  display:flex; align-items:center; justify-content:space-between;
  gap:16px; margin-bottom:16px; font-size:13px; color:var(--ink-2);
}
.sort-wrap{ display:flex; align-items:center; gap:8px; }
.sort-wrap select{
  font:inherit; font-size:13px; border:1px solid var(--line); background:#fff;
  border-radius:9px; padding:6px 10px; color:var(--ink);
}

.grid{
  display:grid; gap:18px;
  grid-template-columns:repeat(auto-fill,minmax(255px,1fr));
}

/* ============ Card ============ */
.card{
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius);
  overflow:hidden; box-shadow:var(--shadow); cursor:pointer;
  display:flex; flex-direction:column;
  transition:transform .16s ease, box-shadow .16s ease, border-color .16s;
}
.card:hover{ transform:translateY(-3px); box-shadow:var(--shadow-lg); border-color:#d6dae1; }
.card-media{
  position:relative; background:#f1f2f4; aspect-ratio:4/3; overflow:hidden;
}
.card-media img{
  width:100%; height:100%; object-fit:contain; padding:6px;
  transition:transform .3s ease;
}
.card:hover .card-media img{ transform:scale(1.045); }
.card-cat{
  position:absolute; top:10px; left:10px;
  background:rgba(255,255,255,.94); border:1px solid var(--line);
  border-radius:999px; padding:3px 9px; font-size:11px; font-weight:600; color:var(--ink-2);
}
.card-n{
  position:absolute; bottom:10px; right:10px;
  background:rgba(29,33,41,.86); color:#fff;
  border-radius:999px; padding:3px 10px; font-size:11px; font-weight:600;
}
.card-body{ padding:13px 14px 15px; display:flex; flex-direction:column; gap:5px; flex:1; }
.card-en{ font-size:10.5px; font-weight:700; letter-spacing:.5px; color:var(--ink-2); text-transform:uppercase; }
.card-th{ font-size:15px; font-weight:700; line-height:1.35; }
.card-codes{ font-size:11.5px; color:var(--ink-2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.card-price{ margin-top:auto; padding-top:9px; font-size:15px; font-weight:800; color:var(--accent); }
.card-price small{ font-size:11px; font-weight:600; color:var(--ink-2); }

/* ============ Modal ============ */
.modal{ position:fixed; inset:0; z-index:60; display:grid; place-items:center; padding:22px; }
.modal-backdrop{ position:absolute; inset:0; background:rgba(15,18,24,.55); backdrop-filter:blur(3px); }
.modal-box{
  position:relative; background:#fff; border-radius:18px; overflow:hidden;
  width:min(1000px,100%); max-height:92vh; box-shadow:var(--shadow-lg);
  display:flex; flex-direction:column;
  animation:pop .18s ease;
}
@keyframes pop{ from{ opacity:0; transform:translateY(10px) scale(.985);} }
.modal-x{
  position:absolute; top:12px; right:12px; z-index:3;
  width:34px; height:34px; border-radius:50%; border:1px solid var(--line);
  background:rgba(255,255,255,.95); font-size:22px; line-height:1; color:var(--ink-2);
}
.modal-x:hover{ background:#fff; color:var(--ink); }
.modal-grid{ display:grid; grid-template-columns:1fr 1fr; overflow:hidden; min-height:0; }
.modal-media{
  position:relative; background:#f1f2f4; display:grid; place-items:center;
  padding:16px; cursor:zoom-in; min-height:0; overflow:auto;
}
.modal-media img{ max-height:74vh; width:auto; object-fit:contain; }
.zoom-hint{
  position:absolute; bottom:14px; left:50%; transform:translateX(-50%);
  display:flex; align-items:center; gap:7px;
  background:rgba(29,33,41,.85); color:#fff; border:0;
  border-radius:999px; padding:7px 14px; font-size:12px; font-weight:600;
  pointer-events:none;
}
.modal-info{ padding:26px 26px 22px; overflow-y:auto; }
.m-en{ margin:0 0 3px; font-size:11px; font-weight:700; letter-spacing:.7px; color:var(--ink-2); text-transform:uppercase; }
.m-th{ margin:0 0 6px; font-size:22px; line-height:1.3; }
.m-color{ margin:0 0 16px; font-size:12.5px; color:var(--accent); font-weight:600; }
.m-color:empty{ display:none; }

/* item rows */
.items{ display:flex; flex-direction:column; gap:9px; }
.item{
  display:grid; grid-template-columns:1fr auto; gap:6px 12px;
  border:1px solid var(--line); border-radius:12px; padding:11px 13px;
  transition:border-color .15s, background .15s;
}
.item:hover{ border-color:#c9ced7; }
.item.off{ opacity:.55; background:#fafbfc; }
.item-main{ min-width:0; }
.item-code{ font-weight:800; font-size:14px; letter-spacing:.2px; }
.item-size{ font-size:11.5px; color:var(--ink-2); margin-top:1px; }
.item-note{ font-size:11px; color:var(--accent); margin-top:2px; }
.item-right{ display:flex; align-items:center; gap:10px; }
.item-price{ font-size:15px; font-weight:800; white-space:nowrap; }
.item-price small{ font-size:10.5px; font-weight:600; color:var(--ink-2); }
.tag{
  display:inline-block; font-size:10.5px; font-weight:700; border-radius:6px;
  padding:2px 7px; white-space:nowrap;
}
.tag.mto{ background:#fff4e5; color:#a35b00; }
.tag.disc{ background:#f1f2f4; color:#6b7280; }
.tag.soon{ background:#e7f2ff; color:#0b5cad; }

/* ---- เลือกสี ---- */
.item-colors{
  grid-column:1 / -1; display:flex; flex-wrap:wrap; align-items:center; gap:6px;
  margin-top:9px; padding-top:9px; border-top:1px dashed var(--line);
}
.colors-label{ font-size:11.5px; color:var(--ink-2); font-weight:600; margin-right:2px; }
.chip{
  display:inline-flex; align-items:center; gap:6px;
  border:1px solid var(--line); background:#fff; color:var(--ink);
  border-radius:999px; padding:4px 11px 4px 5px; font-size:12px; font-weight:600;
  transition:.14s;
}
.chip i{
  width:15px; height:15px; border-radius:50%; flex:none;
  border:1px solid rgba(0,0,0,.16); box-shadow:inset 0 -1px 2px rgba(0,0,0,.07);
}
.chip:hover{ border-color:#b6bcc6; }
.chip.on{ border-color:var(--ink); background:var(--ink); color:#fff; }
.chip.on i{ border-color:rgba(255,255,255,.4); }
.chip.locked{ cursor:default; }
.item.need{ border-color:var(--accent); background:var(--accent-soft); }
.item.need .colors-label{ color:var(--accent); }

.qty{ display:flex; align-items:center; border:1px solid var(--line); border-radius:9px; overflow:hidden; }
.qty button{ width:28px; height:30px; border:0; background:#f7f8fa; color:var(--ink); font-size:15px; line-height:1; }
.qty button:hover{ background:#eceef1; }
.qty input{
  width:40px; height:30px; border:0; text-align:center; font:inherit; font-size:13px; font-weight:600;
  -moz-appearance:textfield; outline:0;
}
.qty input::-webkit-outer-spin-button,.qty input::-webkit-inner-spin-button{ -webkit-appearance:none; margin:0; }
.add{
  border:0; border-radius:9px; background:var(--dark); color:#fff;
  height:30px; padding:0 13px; font-size:12.5px; font-weight:700;
  transition:.15s;
}
.add:hover{ background:#000; }
.add:disabled{ background:#dfe2e7; color:#9aa1ad; cursor:not-allowed; }
.add.done{ background:var(--ok); }

/* ============ Lightbox ============ */
.lightbox{
  position:fixed; inset:0; z-index:90; background:rgba(10,12,16,.94);
  display:grid; place-items:center; padding:40px 20px; cursor:zoom-out;
}
.lightbox img{ max-width:100%; max-height:88vh; object-fit:contain; border-radius:6px; }
.lb-cap{ color:#c7ccd4; font-size:13px; margin:14px 0 0; }
.lb-x{
  position:absolute; top:18px; right:20px; width:42px; height:42px;
  border-radius:50%; border:1px solid rgba(255,255,255,.28);
  background:rgba(255,255,255,.08); color:#fff; font-size:26px; line-height:1;
}

/* ============ Cart ============ */
.cart{ position:fixed; inset:0; z-index:80; }
.cart-backdrop{ position:absolute; inset:0; background:rgba(15,18,24,.5); }
.cart-panel{
  position:absolute; top:0; right:0; height:100%; width:min(430px,100%);
  background:#fff; display:flex; flex-direction:column;
  box-shadow:var(--shadow-lg); animation:slide .2s ease;
}
@keyframes slide{ from{ transform:translateX(24px); opacity:.4; } }
.cart-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:18px 20px; border-bottom:1px solid var(--line); position:relative;
}
.cart-head h2{ margin:0; font-size:17px; }
.cart-head .modal-x{ position:static; }
.cart-body{ flex:1; overflow-y:auto; padding:14px 16px; display:flex; flex-direction:column; gap:10px; }
.cart-empty{ text-align:center; color:var(--ink-2); padding:56px 20px; font-size:14px; }
.cart-empty div{ font-size:40px; margin-bottom:10px; }

.crow{
  display:grid; grid-template-columns:56px 1fr auto; gap:11px; align-items:center;
  border:1px solid var(--line); border-radius:12px; padding:9px;
}
.crow img{ width:56px; height:56px; object-fit:contain; background:#f3f4f6; border-radius:8px; }
.crow-info{ min-width:0; }
.crow-code{ font-weight:800; font-size:13.5px; display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.crow-color{
  display:inline-flex; align-items:center; gap:4px; font-size:10.5px; font-weight:600;
  color:var(--ink-2); background:#f4f5f7; border-radius:999px; padding:2px 8px 2px 3px;
}
.crow-color i{ width:11px; height:11px; border-radius:50%; border:1px solid rgba(0,0,0,.16); }
.crow-sub{ font-size:11px; color:var(--ink-2); margin-top:1px; line-height:1.4; }
.crow-right{ text-align:right; display:flex; flex-direction:column; align-items:flex-end; gap:6px; }
.crow-total{ font-weight:800; font-size:13.5px; white-space:nowrap; }
.crow-del{ border:0; background:transparent; color:#9aa1ad; font-size:11.5px; padding:0; }
.crow-del:hover{ color:var(--accent); }
.qty.sm button{ width:24px; height:26px; font-size:13px; }
.qty.sm input{ width:34px; height:26px; font-size:12px; }

.cart-foot{ border-top:1px solid var(--line); padding:16px 20px 20px; background:#fbfbfc; }
.sum-row{ display:flex; justify-content:space-between; align-items:baseline; font-size:13.5px; color:var(--ink-2); margin-bottom:7px; }
.sum-row strong{ color:var(--ink); font-size:14.5px; }
.sum-row.total{ font-size:15px; color:var(--ink); padding-top:9px; border-top:1px dashed var(--line); }
.sum-row.total strong{ font-size:21px; color:var(--accent); }
.vat-row{ display:flex; align-items:center; gap:7px; font-size:12.5px; color:var(--ink-2); margin-bottom:9px; cursor:pointer; }
.cart-actions{ display:flex; gap:8px; margin-top:14px; }
.btn{ flex:1; border-radius:10px; height:42px; font-size:13px; font-weight:700; border:1px solid var(--line); transition:.15s; }
.btn.ghost{ background:#fff; color:var(--ink-2); }
.btn.ghost:hover{ color:var(--ink); border-color:#c9ced7; }
.btn.primary{ background:var(--accent); border-color:var(--accent); color:#fff; flex:1.4; }
.btn.primary:hover{ background:#a80d26; }

/* ============ Misc ============ */
.empty{ text-align:center; padding:80px 20px; color:var(--ink-2); }
.empty-ico{ font-size:44px; margin-bottom:10px; }
.foot{ border-top:1px solid var(--line); background:#fff; padding:22px 20px; text-align:center; font-size:12px; color:var(--ink-2); }
.toast{
  position:fixed; left:50%; bottom:28px; transform:translate(-50%,20px);
  background:var(--dark); color:#fff; padding:11px 20px; border-radius:11px;
  font-size:13.5px; font-weight:600; opacity:0; pointer-events:none;
  transition:.22s ease; z-index:100; box-shadow:var(--shadow-lg);
}
.toast.on{ opacity:1; transform:translate(-50%,0); }

/* ============ Responsive ============ */
@media (max-width:900px){
  .modal-grid{ grid-template-columns:1fr; }
  .modal-media{ max-height:44vh; }
  .modal-media img{ max-height:40vh; }
  .modal-info{ padding:20px; }
}
@media (max-width:720px){
  .topbar-inner{ flex-wrap:wrap; gap:10px 12px; padding:10px 14px; }
  .search-wrap{ order:3; width:100%; max-width:none; flex-basis:100%; }
  .brand-text span{ display:none; }
  .cart-btn span{ display:none; }
  .cart-btn{ padding:0 13px; }
  .wrap{ padding:16px 14px 50px; }
  .cats{ padding:0 14px 10px; }
  .grid{ grid-template-columns:repeat(auto-fill,minmax(158px,1fr)); gap:12px; }
  .card-th{ font-size:13.5px; }
  .modal{ padding:0; }
  .modal-box{ width:100%; height:100%; max-height:100%; border-radius:0; }
  .item{ grid-template-columns:1fr; }
  .item-right{ justify-content:space-between; }
}

/* ============ Print ============ */
@media print{
  .topbar,.foot,.cart-actions,.card,.results-bar,.modal,.lightbox,.toast{ display:none !important; }
  .cart,.cart-panel{ position:static !important; width:100% !important; box-shadow:none !important; }
  .cart-backdrop,.cart-head .modal-x{ display:none !important; }
  body{ background:#fff; }
}
