:root{
  --bg:#f4f6fb;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --line:#e5e7eb;
  --brand:#16a34a;
  --brand2:#10b981;
  --warn:#f59e0b;
  --shadow: 0 10px 25px rgba(15,23,42,.08);
}
*{box-sizing:border-box}
body{
  margin:0;
  font-family: system-ui,-apple-system,"Kanit",Segoe UI,Roboto,Arial;
  background:var(--bg);
  color:var(--text);
}
a{color:inherit;text-decoration:none}
.container{max-width:1200px;margin:0 auto;padding:20px}
.topbar{
  background:#fff;
  border-bottom:1px solid var(--line);
  position:sticky; top:0; z-index:50;
}
.topbar .row{
  display:flex; align-items:center; justify-content:space-between;
  gap:12px; padding:14px 20px; max-width:1200px; margin:0 auto;
}
.brand{
  display:flex; align-items:center; gap:10px; font-weight:800;
}
.brand .dot{
  width:34px;height:34px;border-radius:10px;
  background:linear-gradient(135deg,var(--brand),var(--brand2));
  box-shadow:0 10px 20px rgba(16,185,129,.25);
}
.brand span{font-size:20px}
.actions{display:flex; align-items:center; gap:10px}
.badge{
  display:inline-flex; align-items:center; gap:8px;
  padding:10px 12px; border:1px solid var(--line); border-radius:12px;
  background:#fff;
}
.badge b{font-weight:800}
.layout{
  display:grid;
  grid-template-columns: 320px 1fr;
  gap:18px;
  align-items:start;
}
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:var(--shadow);
}
.p{padding:16px}
.h{
  font-weight:800;
  margin:0 0 10px 0;
}
.muted{color:var(--muted)}
.btn{
  display:inline-flex;align-items:center;justify-content:center;
  gap:8px;
  padding:10px 14px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  font-weight:700;
}
.btn.primary{
  background:linear-gradient(135deg,var(--warn),#fb923c);
  border:none;
  color:#111827;
}
.btn.green{
  background:linear-gradient(135deg,var(--brand),var(--brand2));
  border:none;
  color:white;
}
.search-bar .btn,
.search-bar button,
.search-bar a {
  white-space: nowrap;
  min-width: 90px;
  text-align: center;
}
.input{
  width:100%;
  padding:11px 12px;
  border-radius:12px;
  border:1px solid var(--line);
  outline:none;
}
.hero{
  overflow:hidden;
  border-radius:18px;
  border:1px solid var(--line);
  background:
    radial-gradient(1200px 400px at 0% 0%, rgba(16,185,129,.18), transparent 60%),
    radial-gradient(900px 350px at 100% 0%, rgba(245,158,11,.18), transparent 60%),
    #0b1220;
  color:white;
  min-height:160px;
  position:relative;
}
.hero .inner{
  padding:22px;
  display:flex;
  justify-content:space-between;
  gap:16px;
  align-items:flex-end;
}
.hero h1{margin:0;font-size:26px;letter-spacing:.2px}
.hero p{margin:8px 0 0 0;color:rgba(255,255,255,.8)}
.hero .pill{
  display:inline-flex;
  padding:10px 12px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
  font-weight:800;
  gap:10px;
}
.grid{
  display:grid;
  grid-template-columns: repeat(4, 1fr);
  gap:14px;
}
.product{
  background:#fff;
  border:1px solid var(--line);
  border-radius:16px;
  overflow:hidden;
  box-shadow:0 12px 26px rgba(15,23,42,.06);
  display:flex; flex-direction:column;
}
.product .img{
  height:180px; background:#0b1220;
  display:flex; align-items:center; justify-content:center;
}
.product img{width:100%;height:100%;object-fit:cover}
/* ปุ่มในสินค้าให้เท่ากัน */
.product .body > div:last-child {
  display: flex;
  gap: 10px;
}

.product .body > div:last-child .btn,
.product .body > div:last-child form {
  flex: 1;
}

.product .body > div:last-child .btn {
  width: 100%;
  text-align: center;
  white-space: nowrap;
}
.product .btn {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 12px;
}
.product .name{font-weight:800; line-height:1.25}
.product .price{
  margin-top:8px;
  font-weight:900;
  color:var(--brand);
}
.product .meta{
  display:flex; justify-content:space-between; align-items:center;
  margin-top:10px;
}
.tag{
  font-size:12px;
  font-weight:900;
  padding:6px 10px;
  border-radius:999px;
  background:#eef2ff;
  color:#3730a3;
}
.tag.sale{background:#fff7ed;color:#9a3412}
.tag.new{background:#ecfdf5;color:#065f46}
.catlist a{
  display:flex; justify-content:space-between; align-items:center;
  padding:10px 10px;
  border-radius:12px;
}
.catlist a:hover{background:#f3f4f6}
.catlist .active{background:#ecfdf5;border:1px solid #bbf7d0}
.hr{height:1px;background:var(--line);margin:12px 0}
.pager{
  display:flex; gap:8px; justify-content:center;
  margin-top:16px;
}
.pager a{
  padding:10px 12px;border-radius:12px;border:1px solid var(--line);
  background:#fff; font-weight:800;
}
.footer{
  margin-top:28px; padding:22px 0; color:var(--muted);
  text-align:center;
}

/* responsive */
@media (max-width:1100px){
  .grid{grid-template-columns: repeat(3,1fr);}
  .layout{grid-template-columns: 300px 1fr;}
}
@media (max-width:900px){
  .layout{grid-template-columns:1fr;}
  .grid{grid-template-columns: repeat(2,1fr);}
}
@media (max-width:520px){
  .grid{grid-template-columns:1fr;}
}
/* ===== Responsive Patch ===== */

/* ป้องกันคำไทยแตกเป็นแนวตั้งในปุ่ม/ลิงก์ */
a, button, .btn, .badge, .pill {
  word-break: normal;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* รูปภาพไม่ล้น */
img { max-width: 100%; height: auto; }

/* <= 1100px: 3 columns */
@media (max-width: 1100px){
  .container{ padding:16px; }
  .layout{ grid-template-columns: 300px 1fr; }
  .grid{ grid-template-columns: repeat(3, 1fr); }
}

/* <= 900px: sidebar ลงล่าง + 2 columns */
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; }
  .grid{ grid-template-columns: repeat(2, 1fr); }

  .topbar .row{
    flex-wrap: wrap;
    gap:10px;
  }
  .actions{
    width:100%;
    justify-content:flex-end;
    flex-wrap: wrap;
    gap:8px;
  }
  .badge{
    padding:8px 10px;
    border-radius:12px;
  }

  .hero .inner{
    flex-direction: column;
    align-items:flex-start;
  }
  .hero h1{ font-size:22px; }
}

/* <= 520px: 1 column + header แน่นขึ้น */
@media (max-width: 520px){
  .container{ padding:12px; }
  .grid{ grid-template-columns: 1fr; }

  .topbar .row{
    padding:12px 12px;
  }
  .brand span{ font-size:18px; }
  .brand .dot{ width:30px; height:30px; border-radius:10px; }

  .badge{
    width:auto;
    max-width: 100%;
  }

  /* ทำให้ปุ่ม/แท็กไม่แคบจนตัวหนังสือตั้ง */
  .btn, .badge{
    min-height: 42px;
    white-space: nowrap; /* สำคัญ: กันคำไทยตั้ง */
  }

  /* ถ้าอยากให้ badge ลงบรรทัดสวยๆ ให้ใช้บรรทัดนี้แทนด้านบน */
  /* .btn, .badge{ white-space: normal; } */

  .hero{ min-height: 150px; }
  .hero .pill{ font-size:12px; }
}

/* การ์ดสินค้าให้สวยบนมือถือ */
@media (max-width: 520px){
  .product .img{ height: 200px; }
  .product .body{ padding: 12px; }
  .product .name{ font-size: 16px; }
}

/* ===== Admin Dashboard UI ===== */
.admin-wrap{max-width:1200px;margin:0 auto;padding:22px;}
.admin-top{
  display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;
  margin-bottom:14px;
}
.admin-title h1{margin:0;font-size:22px;letter-spacing:.2px;}
.admin-title .sub{color:var(--muted);margin-top:4px;font-size:13px;}

.admin-nav{display:flex;gap:10px;flex-wrap:wrap;align-items:center;}
.admin-nav a{
  padding:10px 14px;border-radius:14px;border:1px solid var(--line);background:#fff;
  font-weight:800; box-shadow:0 10px 24px rgba(15,23,42,.06);
}
.admin-nav a:hover{transform:translateY(-1px);transition:.15s;}
.admin-nav a.primary{
  background:linear-gradient(135deg,var(--brand),var(--brand2));color:#fff;border:none;
}

.kpi-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:14px;
  margin-top:14px;
}
.kpi{
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 18px 40px rgba(15,23,42,.07);
  padding:16px;
  position:relative;
  overflow:hidden;
}
.kpi:before{
  content:"";
  position:absolute; inset:auto -80px -80px auto;
  width:200px;height:200px;border-radius:50%;
  background:radial-gradient(circle at 30% 30%, rgba(16,185,129,.25), transparent 60%);
}
.kpi .row{display:flex;justify-content:space-between;align-items:flex-start;gap:10px;}
.kpi .label{color:var(--muted);font-weight:700;}
.kpi .value{font-size:34px;font-weight:950;line-height:1;margin-top:8px;}
.kpi .hint{color:var(--muted);font-size:12px;margin-top:10px;}
.kpi .icon{
  width:44px;height:44px;border-radius:14px;
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,#eef2ff,#ecfeff);
  border:1px solid var(--line);
  font-size:20px;
}
.kpi.green .icon{background:linear-gradient(135deg,#ecfdf5,#d1fae5);}
.kpi.orange .icon{background:linear-gradient(135deg,#fff7ed,#ffedd5);}
.kpi.blue .icon{background:linear-gradient(135deg,#eff6ff,#dbeafe);}

.panel-grid{
  display:grid;
  grid-template-columns: 1.2fr .8fr;
  gap:14px;
  margin-top:14px;
}
.panel{
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 18px 40px rgba(15,23,42,.07);
  overflow:hidden;
}
.panel .head{
  padding:14px 16px;border-bottom:1px solid var(--line);
  display:flex;justify-content:space-between;align-items:center;gap:10px;
}
.panel .head .t{font-weight:900;}
.panel .body{padding:14px 16px;}

.table{width:100%;border-collapse:collapse;}
.table th,.table td{padding:10px 8px;border-bottom:1px solid #eef2f7;text-align:left;font-size:14px;}
.table th{color:var(--muted);font-weight:800;font-size:12px;text-transform:uppercase;letter-spacing:.08em;}
.status{
  display:inline-flex;align-items:center;gap:6px;
  padding:6px 10px;border-radius:999px;font-weight:900;font-size:12px;border:1px solid var(--line);
  background:#f8fafc;color:#0f172a;
}
.status.pending{background:#fff7ed;color:#9a3412;border-color:#fed7aa;}
.status.paid{background:#ecfdf5;color:#065f46;border-color:#bbf7d0;}
.status.packing{background:#eff6ff;color:#1d4ed8;border-color:#bfdbfe;}
.status.shipped{background:#f5f3ff;color:#6d28d9;border-color:#ddd6fe;}
.status.completed{background:#f0fdf4;color:#166534;border-color:#bbf7d0;}
.status.cancelled{background:#fef2f2;color:#991b1b;border-color:#fecaca;}

.quick{
  display:grid;grid-template-columns:1fr 1fr;gap:10px;
}
.quick a{display:flex;gap:10px;align-items:center;justify-content:space-between;
  padding:12px 14px;border-radius:16px;border:1px solid var(--line);background:#fff;
  box-shadow:0 10px 24px rgba(15,23,42,.06);font-weight:900;
}
.quick a span{color:var(--muted);font-weight:800;font-size:12px;}
.quick a:hover{transform:translateY(-1px);transition:.15s;}

@media (max-width:1100px){
  .kpi-grid{grid-template-columns:repeat(2,1fr);}
  .panel-grid{grid-template-columns:1fr;}
}
@media (max-width:520px){
  .admin-wrap{padding:14px;}
  .kpi-grid{grid-template-columns:1fr;}
  .quick{grid-template-columns:1fr;}
}

/* ===== Product Page ===== */
.pd-wrap{max-width:1200px;margin:0 auto;padding:20px;}
.pd-hero{
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 18px 40px rgba(15,23,42,.07);
  overflow:hidden;
}
.pd-grid{display:grid;grid-template-columns: 1.05fr .95fr; gap:0;}
.pd-media{padding:18px;border-right:1px solid var(--line); background:linear-gradient(135deg,#0b1220,#0f1b33);}
.pd-media .frame{
  border-radius:16px; overflow:hidden;
  background:#0b1220; border:1px solid rgba(255,255,255,.12);
  aspect-ratio: 1 / 1;
  display:flex; align-items:center; justify-content:center;
}
.pd-media img{width:100%;height:100%;object-fit:cover;display:block;}
.pd-info{padding:18px;background:#fff;}
.pd-title{margin:0;font-size:28px;line-height:1.2;font-weight:950;}
.pd-price{margin-top:10px;font-size:26px;font-weight:950;color:var(--brand);}
.pd-old{color:var(--muted);text-decoration:line-through;font-weight:800;margin-left:8px;font-size:15px;}
.pd-tags{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px;}
.pd-tag{
  padding:7px 10px;border-radius:999px;font-weight:950;font-size:12px;
  border:1px solid var(--line); background:#f8fafc;color:#0f172a;
}
.pd-tag.new{background:#ecfdf5;color:#065f46;border-color:#bbf7d0;}
.pd-tag.sale{background:#fff7ed;color:#9a3412;border-color:#fed7aa;}
.pd-tag.stock{background:#eff6ff;color:#1d4ed8;border-color:#bfdbfe;}

.pd-desc{margin-top:14px;color:#334155;line-height:1.7;}
.pd-actions{
  margin-top:16px; display:flex; gap:10px; flex-wrap:wrap;
}
.pd-actions .btn{height:46px;border-radius:14px;font-weight:950;}
.pd-actions .btn{white-space:nowrap;}
.pd-actions form{margin:0;}

.pd-buyrow{
  margin-top:14px;
  display:flex; gap:10px; align-items:center; flex-wrap:wrap;
}
.qty{
  display:flex; align-items:center; gap:8px;
  border:1px solid var(--line); border-radius:14px; padding:8px 10px; background:#fff;
}
.qty input{
  width:70px; border:none; outline:none; font-weight:900; text-align:center;
}
.qty button{
  width:34px;height:34px;border-radius:12px;border:1px solid var(--line);
  background:#fff;cursor:pointer;font-weight:900;
}
.pd-meta{
  margin-top:14px;
  display:grid; grid-template-columns:1fr 1fr; gap:10px;
}
.pd-box{
  border:1px solid var(--line); border-radius:16px; padding:12px; background:#fff;
}
.pd-box .k{color:var(--muted);font-weight:800;font-size:12px;}
.pd-box .v{font-weight:950;margin-top:4px;}

.pd-related{
  margin-top:16px;
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 18px 40px rgba(15,23,42,.07);
  padding:16px;
}
.pd-related .head{display:flex;justify-content:space-between;align-items:end;gap:10px;}
.pd-related .head .t{font-weight:950;font-size:16px;}
.pd-related .head .m{color:var(--muted);font-size:13px;}
.pd-related .grid{margin-top:12px;}

@media (max-width: 900px){
  .pd-grid{grid-template-columns:1fr;}
  .pd-media{border-right:none;border-bottom:1px solid var(--line);}
  .pd-title{font-size:22px;}
  .pd-price{font-size:22px;}
  .pd-meta{grid-template-columns:1fr;}
}
/* ===== Admin Form UI ===== */
.af-wrap{max-width:980px;margin:0 auto;padding:22px;}
.af-top{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;margin-bottom:12px;}
.af-title{font-size:20px;font-weight:950;margin:0;}
.af-sub{color:var(--muted);font-size:13px;margin-top:4px;}

.af-card{
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 18px 40px rgba(15,23,42,.07);
  overflow:hidden;
}
.af-card .head{
  padding:14px 16px;border-bottom:1px solid var(--line);
  display:flex;justify-content:space-between;align-items:center;gap:10px;
  background:linear-gradient(135deg,#ffffff,#f8fafc);
}
.af-card .head .t{font-weight:950;}
.af-card .body{padding:16px;}

.af-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;}
.af-grid3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px;}
@media (max-width:900px){ .af-grid,.af-grid3{grid-template-columns:1fr;} }

.field{display:flex;flex-direction:column;gap:6px;}
.field label{font-weight:900;font-size:13px;}
.help{color:var(--muted);font-size:12px;line-height:1.45;}
.req{color:#ef4444;font-weight:950;margin-left:4px;}

.input, textarea, select{
  border-radius:14px !important;
  border:1px solid var(--line) !important;
  padding:12px 12px !important;
  font-weight:700;
}
textarea{resize:vertical;min-height:120px;}

.af-row{
  display:flex;gap:10px;align-items:center;flex-wrap:wrap;
}
.pill{
  display:inline-flex;align-items:center;gap:8px;
  padding:8px 10px;border-radius:999px;
  border:1px solid var(--line);background:#fff;font-weight:900;
}
.pill small{color:var(--muted);font-weight:800;}
.preview{
  padding:12px 14px;border-radius:16px;border:1px dashed #cbd5e1;background:#f8fafc;
}
.preview b{font-weight:950;}
.preview .ok{color:var(--brand);font-weight:950;}
.preview .warn{color:#b45309;font-weight:950;}
.af-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:14px;}