:root {
  --bg: #0a0c10;
  --bg2: #0e1217;
  --card: #12161d;
  --card2: #171c25;
  --line: #232a34;
  --line2: #2c3540;
  --text: #e8ecf1;
  --muted: #8b97a6;
  --faint: #5b6573;
  --green: #2ea36b;
  --green2: #268a5a;
  --gold: #c9a45c;
  --red: #d05c54;
  --blue: #5b8def;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --nav-bg: rgba(10,12,16,.82);
}
:root[data-theme="light"] { --nav-bg: rgba(255,255,255,.82); }
/* โหมดสว่าง (ปรับจากหลังบ้าน) */
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --bg2: #eef1f5;
  --card: #ffffff;
  --card2: #f5f7fa;
  --line: #e3e7ed;
  --line2: #d3d9e1;
  --text: #1b2330;
  --muted: #5c6b7e;
  --faint: #94a1b2;
  --shadow: 0 10px 30px rgba(25,40,65,.08);
  --shadow-sm: 0 2px 8px rgba(25,40,65,.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", "Kanit", "Sarabun", "Segoe UI", system-ui, sans-serif;
  font-size: 15px; line-height: 1.6; letter-spacing: .1px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; transition: color .15s; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.01em; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.green { color: var(--green); }
.gold { color: var(--gold); }
.red { color: var(--red); }
.center { text-align: center; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.spread { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap: wrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .18em; font-size: .72rem; font-weight: 600; color: var(--muted); }

/* ---------- Icons ---------- */
.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -3.5px; flex: none; }
.ic-lg { width: 26px; height: 26px; }
.ic-xl { width: 40px; height: 40px; stroke-width: 1.4; }

/* ---------- Navbar ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: var(--nav-bg); backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.nav-inner { display: flex; align-items: center; gap: 22px; height: 66px; }
.brand { font-weight: 600; font-size: 1.15rem; display: flex; align-items: center; gap: 11px; letter-spacing: .01em; }
.brand-logo { height: 30px; width: auto; max-width: 150px; object-fit: contain; display: block; }
.brand .cube { width: 22px; height: 22px; border: 1.5px solid var(--green); border-radius: 5px; position: relative; }
.brand .cube::after { content:""; position:absolute; inset:4px; background: var(--green); border-radius: 2px; opacity:.85; }
.nav-links { display: flex; gap: 26px; margin-left: 6px; }
.nav-links a { color: var(--muted); font-weight: 500; font-size: .92rem; padding: 6px 0; position: relative; }
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--text); }
.nav-links a.active::after { content:""; position:absolute; left:0; right:0; bottom:-2px; height:2px; background: var(--green); border-radius:2px; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; color: var(--muted); }
.search input { background: transparent; border: 0; color: var(--text); outline: none; width: 150px; font-size: .9rem; }
.icon-btn { position: relative; display:flex; align-items:center; justify-content:center; width:40px; height:40px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); }
.icon-btn:hover { color: var(--text); border-color: var(--line2); }
.cart-badge { position: absolute; top: -7px; right: -7px; background: var(--green); color: #04130b; border-radius: 999px; font-size: .68rem; min-width: 18px; height:18px; display:flex; align-items:center; justify-content:center; padding: 0 5px; font-weight: 700; }
.menu-toggle { display:none; background:var(--card); border:1px solid var(--line); color:var(--text); border-radius:8px; width:40px; height:40px; align-items:center; justify-content:center; }
.user-chip { display:flex; align-items:center; gap:9px; background: var(--card); border:1px solid var(--line); border-radius: 8px; padding: 6px 13px; font-size: .88rem; font-weight: 500; }
.user-chip .bal { color: var(--gold); font-weight: 600; }
.user-chip:hover { border-color: var(--line2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content:center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line2); background: var(--card2); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-weight: 500; font-size: .9rem; transition: .15s;
  font-family: inherit; letter-spacing: .01em; }
.btn:hover { border-color: var(--faint); background: #1c222c; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-gold { background: transparent; border-color: var(--gold); color: var(--gold); font-weight: 600; }
.btn-gold:hover { background: rgba(201,164,92,.1); border-color: var(--gold); }
.btn-danger { background: transparent; border-color: rgba(208,92,84,.5); color: var(--red); }
.btn-danger:hover { background: rgba(208,92,84,.1); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--card); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: .82rem; }
.btn-lg { padding: 13px 26px; font-size: .98rem; }
.btn:disabled { opacity:.45; cursor: not-allowed; }
.ic-btn-pair .ic { width:16px; height:16px; }

/* ---------- Cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.product { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: .2s; }
.product:hover { transform: translateY(-3px); border-color: var(--line2); box-shadow: var(--shadow); }
.product .thumb { aspect-ratio: 16/10; background: var(--bg2);
  display:flex; align-items:center; justify-content:center; color: var(--faint); position: relative; border-bottom: 1px solid var(--line); }
.product .thumb .cat-ic { font-size: 2rem; opacity:.5; }
.product .body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.product .name { font-weight: 600; font-size: .98rem; }
.product .desc { color: var(--muted); font-size: .83rem; flex:1; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.product .price { color: var(--gold); font-weight: 600; font-size: 1.1rem; letter-spacing: .01em; }
.product .price small { color: var(--muted); font-weight: 400; font-size: .7rem; }

.badge { display:inline-flex; align-items:center; gap:5px; font-size:.72rem; font-weight:500; padding:3px 10px; border-radius:6px; background:var(--card2); border:1px solid var(--line); color:var(--muted); letter-spacing: .02em; }
.badge .ic { width:13px; height:13px; }
.badge.green { background: rgba(46,163,107,.12); color: var(--green); border-color: rgba(46,163,107,.25); }
.badge.gold { background: rgba(201,164,92,.12); color: var(--gold); border-color: rgba(201,164,92,.25); }
.badge.red { background: rgba(208,92,84,.12); color: var(--red); border-color: rgba(208,92,84,.25); }
.badge.blue { background: rgba(91,141,239,.12); color: var(--blue); border-color: rgba(91,141,239,.25); }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden;
  background:
    radial-gradient(900px 360px at 78% -20%, rgba(46,163,107,.18), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line); padding: 72px 0; }
.hero h1 { font-size: 2.7rem; margin: 14px 0 14px; font-weight: 700; line-height: 1.12; letter-spacing: -.02em; }
.hero p { color: var(--muted); font-size: 1.08rem; max-width: 540px; }
.hero .cta { margin-top: 28px; display: flex; gap: 12px; }

.section { padding: 44px 0; }
.section-head { display:flex; align-items:flex-end; justify-content:space-between; margin-bottom: 22px; gap: 14px; }
.section h2 { font-size: 1.4rem; margin: 0; }
.section-head .link { color: var(--muted); font-size: .88rem; display:flex; align-items:center; gap:5px; }
.section-head .link:hover { color: var(--text); }

.cat-chips { display:flex; gap:10px; flex-wrap:wrap; }
.cat-chips a { background: var(--card); border:1px solid var(--line); padding:8px 16px; border-radius:8px; font-weight:500; font-size:.88rem; color:var(--muted); }
.cat-chips a.active, .cat-chips a:hover { color: var(--text); border-color: var(--line2); }

.cat-card { display:flex; flex-direction:column; align-items:center; gap:10px; padding: 26px 16px; font-weight:500; color: var(--text); }
.cat-card .ic { color: var(--green); }
.cat-card:hover { border-color: var(--line2); }

/* ---------- Forms ---------- */
label { font-weight: 500; font-size: .85rem; display:block; margin-bottom:7px; color: var(--text); }
input, select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 13px; border-radius: 8px; font-size: .92rem; font-family: inherit; outline: none; transition: border-color .15s; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 17px; }
.form-narrow { max-width: 420px; margin: 56px auto; }
.form-narrow h1 { font-size: 1.5rem; }
.check { display:flex; align-items:center; gap:9px; font-weight:500; cursor:pointer; }
.check input { width:auto; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: .88rem; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:last-child td { border-bottom: 0; }
tr:hover td { background: rgba(255,255,255,.015); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }

/* ---------- Flash ---------- */
.flash { padding: 13px 16px; border-radius: 8px; margin: 18px 0; font-weight: 500; font-size:.9rem; border:1px solid; display:flex; align-items:center; gap:9px; }
.flash.success { background: rgba(46,163,107,.1); color: var(--green); border-color: rgba(46,163,107,.3); }
.flash.error { background: rgba(208,92,84,.1); color: var(--red); border-color: rgba(208,92,84,.3); }

/* ---------- Cart / checkout ---------- */
.cart-item { display:flex; gap:16px; align-items:center; padding:16px 0; border-bottom:1px solid var(--line); }
.cart-item:last-child { border-bottom: 0; }
.cart-item .icon { width:58px; height:58px; background:var(--bg2); border:1px solid var(--line); border-radius:8px; display:flex; align-items:center; justify-content:center; color: var(--faint); overflow:hidden; }
.qty input { width:64px; text-align:center; }
.summary { position: sticky; top: 86px; }
.summary h3 { margin-top: 0; }
.summary .line { display:flex; justify-content:space-between; padding:7px 0; font-size:.9rem; color: var(--muted); }
.summary .line span:last-child { color: var(--text); }
.summary .total { border-top:1px solid var(--line); margin-top:10px; padding-top:14px; font-size:1.25rem; font-weight:600; color: var(--text); }
.summary .total span:last-child { color: var(--gold); }

.pay-option { border:1px solid var(--line); border-radius:9px; padding:18px; margin-bottom:12px; cursor:pointer; transition:.15s; }
.pay-option:hover { border-color: var(--line2); }
.pay-option.active { border-color: var(--green); background: rgba(46,163,107,.04); }
.pay-option h4 { margin:0; display:flex; align-items:center; gap:10px; font-weight:500; }
.pay-option .sub { color: var(--muted); font-size:.85rem; margin-top:6px; }
.pay-body { display:none; margin-top:16px; }
.pay-option.active .pay-body { display:block; }
.pay-radio { width:18px; height:18px; border:2px solid var(--line2); border-radius:50%; flex:none; position:relative; }
.pay-option.active .pay-radio { border-color: var(--green); }
.pay-option.active .pay-radio::after { content:""; position:absolute; inset:3px; background:var(--green); border-radius:50%; }
.pay-info { background: var(--bg2); border:1px solid var(--line); border-radius:8px; padding:14px; font-size:.88rem; }
.pay-info div { padding: 2px 0; }

/* ---------- Admin ---------- */
.admin { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg2); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top:0; height:100vh; overflow:auto; }
.sidebar .brand { padding: 6px 12px 22px; }
.sidebar .nav-section { font-size:.7rem; text-transform:uppercase; letter-spacing:.12em; color:var(--faint); padding: 14px 12px 6px; }
.sidebar a { display:flex; align-items:center; gap:12px; padding:10px 13px; border-radius:8px; color:var(--muted); font-weight:500; font-size:.9rem; margin-bottom:1px; }
.sidebar a:hover { background: var(--card); color: var(--text); }
.sidebar a.active { background: var(--card); color: var(--green); }
.sidebar a.active .ic { color: var(--green); }
.admin-main { padding: 30px 36px; overflow:auto; }
.stat-grid { display:grid; grid-template-columns: repeat(auto-fit,minmax(168px,1fr)); gap:16px; margin-bottom:26px; }
.stat { background: var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:20px; }
.stat .v { font-size: 1.65rem; font-weight: 600; margin-top:4px; }
.stat .l { color: var(--muted); font-size:.8rem; text-transform:uppercase; letter-spacing:.05em; }
.page-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:24px; gap:14px; flex-wrap:wrap; }
.page-head h1 { margin:0; font-size:1.45rem; }
.tabs { display:flex; gap:8px; margin-bottom:18px; flex-wrap:wrap; }
.tabs a { padding:7px 15px; border-radius:7px; background:var(--card); border:1px solid var(--line); color:var(--muted); font-size:.83rem; font-weight:500; }
.tabs a.active { color:var(--text); border-color:var(--line2); }

/* ---------- Charts ---------- */
.chart-svg { width:100%; height:auto; display:block; }
.chart-svg .grid { stroke: var(--line); stroke-width:1; }
.chart-svg .bar { fill: var(--green); opacity:.85; rx:2; transition: opacity .15s; }
.chart-svg .bar:hover { opacity:1; }
.chart-svg .axis { fill: var(--muted); font-size:10px; }
.chart-svg .line { fill:none; stroke: var(--gold); stroke-width:2; stroke-linejoin:round; stroke-linecap:round; }
.chart-svg .dot { fill: var(--gold); }
.chart-svg .area { fill: var(--gold); opacity:.08; }
.legend { display:flex; gap:16px; font-size:.82rem; color:var(--muted); }
.legend span { display:inline-flex; align-items:center; gap:6px; }
.legend .key { width:11px; height:11px; border-radius:3px; }
.hbar { margin:11px 0; }
.hbar .top { display:flex; justify-content:space-between; font-size:.85rem; margin-bottom:5px; }
.hbar .track { height:8px; background:var(--bg2); border-radius:5px; overflow:hidden; }
.hbar .fill { height:100%; background:var(--green); border-radius:5px; }
.hbar .fill.gold { background:var(--gold); }

footer.site { border-top:1px solid var(--line); padding: 36px 0 0; color: var(--muted); margin-top: 56px; }
footer.site .brand { font-size: 1rem; }
footer.site .credit { margin-top: 28px; padding: 16px 20px; border-top: 1px solid var(--line); text-align: center; font-size: .8rem; color: var(--faint); letter-spacing: .02em; }
footer.site .credit strong { color: var(--green); font-weight: 600; }
.sidebar .credit { margin-top: 14px; padding: 14px 13px 4px; border-top: 1px solid var(--line); font-size: .72rem; color: var(--faint); text-align: center; line-height: 1.7; }
.sidebar .credit strong { color: var(--green); }

.empty { text-align:center; padding:64px 20px; color:var(--muted); }
.empty .ic { color: var(--faint); margin-bottom:14px; }
.inline { display:inline; }
.mt { margin-top:18px; } .mb { margin-bottom:18px; } .mt-sm { margin-top:8px; }
.divider { height:1px; background:var(--line); margin:20px 0; }
code.kbd { background: var(--bg2); border:1px solid var(--line); padding:2px 7px; border-radius:5px; font-size:.85em; font-family: "SF Mono", ui-monospace, monospace; }
pre { font-family: "SF Mono", ui-monospace, monospace; }
details summary { cursor: pointer; }

/* ---------- ลูกเล่น / Micro-interactions ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes badgePop { 0% { transform: scale(1); } 45% { transform: scale(1.55); } 100% { transform: scale(1); } }
@keyframes cubeFloat {
  0%, 100% { transform: translateY(0) rotate(8deg); }
  50% { transform: translateY(-26px) rotate(-6deg); }
}
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes toastBar { from { width: 100%; } to { width: 0; } }

body { animation: fadeUp .35s ease-out; }

/* reveal ตอนเลื่อนถึง */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity .5s ease, transform .5s cubic-bezier(.2,.7,.3,1); }
.reveal.in { opacity: 1; transform: none; }

/* ปุ่ม: กดแล้วยุบนิด ๆ + เงานุ่มตอน hover */
.btn { transition: background .15s, border-color .15s, color .15s, transform .12s, box-shadow .2s; }
.btn:hover { box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.965); }
.btn.busy { opacity: .65; pointer-events: none; }

/* การ์ดสินค้า: รูปซูมนุ่ม ๆ + ราคาไฮไลต์ */
.product .thumb { overflow: hidden; }
.product .thumb img, .product .thumb .ic { transition: transform .45s cubic-bezier(.2,.7,.3,1); }
.product:hover .thumb img { transform: scale(1.06); }
.product:hover .thumb .ic { transform: translateY(-4px) scale(1.12); }
.product:hover .price { text-shadow: 0 0 18px color-mix(in srgb, var(--gold) 35%, transparent); }

/* ช่องกรอก: วงแหวนโฟกัสนุ่ม ๆ */
input:focus, select:focus, textarea:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 16%, transparent);
}

/* badge ตะกร้าเด้ง */
.cart-badge.pop { animation: badgePop .45s cubic-bezier(.3,1.6,.4,1); }

/* toast ลอยมุมขวาบน */
.toast-stack { position: fixed; top: 78px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: min(360px, calc(100vw - 36px)); }
.flash.toast { margin: 0; padding-right: 38px; position: relative; overflow: hidden; box-shadow: var(--shadow); background-color: var(--card); animation: toastIn .3s cubic-bezier(.2,.8,.3,1); }
.flash.toast.out { opacity: 0; transform: translateX(24px); transition: .3s; }
.toast-x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: inherit; font-size: 1.1rem; cursor: pointer; opacity: .6; padding: 2px 6px; }
.toast-x:hover { opacity: 1; }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: currentColor; opacity: .45; animation: toastBar 4.5s linear forwards; }

/* ลูกบาศก์ลอยใน hero */
.hero { position: relative; }
.fcube { position: absolute; border: 1.5px solid var(--green); border-radius: 6px; opacity: .14; pointer-events: none; animation: cubeFloat 7s ease-in-out infinite; }
.fcube.gold { border-color: var(--gold); }
.fcube.fill { background: var(--green); border: 0; opacity: .08; }

/* กราฟแท่งงอกขึ้น + จุดค่อย ๆ โผล่ */
.chart-svg .bar { transform-box: fill-box; transform-origin: bottom; animation: barGrow .55s cubic-bezier(.2,.7,.3,1) backwards; animation-delay: calc(var(--i, 0) * 35ms); }
.chart-svg .line, .chart-svg .dot { animation: fadeUp .5s ease-out .45s backwards; }

/* ปุ่มกลับขึ้นบน */
.to-top { position: fixed; right: 18px; bottom: 18px; z-index: 150; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line2); border-radius: 50%; color: var(--muted);
  cursor: pointer; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .25s; box-shadow: var(--shadow-sm); }
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { color: var(--text); border-color: var(--green); }

/* ตาราง: แถวไฮไลต์นุ่มขึ้น */
tr { transition: background .15s; }

/* ปิดอนิเมชันทั้งหมดถ้าผู้ใช้ตั้ง reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .reveal { opacity: 1; transform: none; }
}

@media (max-width: 880px) {
  .grid-4 { grid-template-columns: repeat(2,1fr); }
  .grid-3 { grid-template-columns: repeat(2,1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .nav-links, .search { display: none; }
  .menu-toggle { display:flex; }
  .nav-links.open { display:flex; position:absolute; top:66px; left:0; right:0; flex-direction:column; gap:0; background:var(--bg2); padding:10px 20px; border-bottom:1px solid var(--line); }
  .nav-links.open a { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .admin { grid-template-columns: 1fr; }
  .sidebar { position:static; height:auto; display:flex; flex-wrap:wrap; gap:4px; }
  .sidebar .brand { width:100%; }
  .sidebar .nav-section { display:none; }
  .admin-main { padding: 22px 18px; }
  .hero { padding: 52px 0; }
  .hero h1 { font-size: 2rem; }
}
