/* ===== BKS Market ===== */
:root {
  --primary: #f4511e;
  --primary-dark: #d84315;
  --primary-light: #ffece5;
  --accent: #00897b;
  --accent-light: #e0f2f1;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2d2a26;
  --muted: #8a8378;
  --border: #ece5da;
  --star: #ffb300;
  --danger: #e53935;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 20, .07);
  --shadow-hover: 0 8px 24px rgba(60, 40, 20, .13);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ===== Top bar ===== */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 6px rgba(60,40,20,.06);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 18px;
}
.brand { font-size: 1.35rem; font-weight: 800; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand em { color: var(--primary); font-style: normal; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 14px; border-radius: 999px; font-weight: 600; color: var(--muted);
  transition: all .15s;
}
.nav a:hover, .nav a.active { background: var(--primary-light); color: var(--primary-dark); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.cart-btn {
  position: relative; font-size: 1.5rem; padding: 4px 8px; border-radius: 10px;
  transition: transform .15s;
}
.cart-btn:hover { transform: scale(1.12); }
.cart-count {
  position: absolute; top: -2px; right: -4px;
  background: var(--primary); color: #fff; font-size: .7rem; font-weight: 700;
  min-width: 19px; height: 19px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.cart-count.empty { display: none; }

.user-chip {
  display: flex; align-items: center; gap: 8px; background: var(--accent-light);
  padding: 5px 12px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  color: var(--accent); cursor: pointer; border: none;
}
.user-menu { position: relative; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-hover); min-width: 190px; overflow: hidden; display: none;
}
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left; padding: 10px 16px;
  border: none; background: none; font-size: .95rem; font-weight: 500;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--primary-light); }

/* ===== Layout ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; width: 100%; flex: 1; }
.footer {
  background: var(--card); border-top: 1px solid var(--border);
  text-align: center; padding: 18px; color: var(--muted); font-size: .85rem;
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(120deg, #ff7043, var(--primary) 55%, #e64a19);
  color: #fff; border-radius: 20px; padding: 36px 32px; margin-bottom: 26px;
  position: relative; overflow: hidden;
}
.hero::after {
  content: '🛍️ 🍡 🧃 ✏️ 🧺'; position: absolute; right: 20px; bottom: 12px;
  font-size: 2rem; opacity: .5; letter-spacing: 8px;
}
.hero h1 { font-size: 1.9rem; font-weight: 800; margin-bottom: 6px; }
.hero p { opacity: .93; max-width: 560px; }
.hero .btn { margin-top: 16px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none;
  padding: 10px 22px; border-radius: 999px; font-weight: 700; font-size: .98rem;
  transition: all .15s; text-align: center;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--card); color: var(--primary-dark); border: 2px solid var(--primary); }
.btn.secondary:hover { background: var(--primary-light); }
.btn.ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--border); }
.btn.ghost:hover { border-color: var(--muted); color: var(--text); }
.btn.accent { background: var(--accent); }
.btn.accent:hover { background: #00695c; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 14px; font-size: .88rem; }
.btn.block { width: 100%; }

/* ===== Search & filters ===== */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.search-box {
  flex: 1; min-width: 220px; display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1.5px solid var(--border); border-radius: 999px;
  padding: 9px 18px;
}
.search-box input { border: none; outline: none; flex: 1; background: none; }
select.select {
  background: var(--card); border: 1.5px solid var(--border); border-radius: 999px;
  padding: 9px 16px; outline: none; font-weight: 500;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.chip {
  background: var(--card); border: 1.5px solid var(--border); border-radius: 999px;
  padding: 6px 16px; font-weight: 600; font-size: .9rem; color: var(--muted);
  transition: all .15s; border: 1.5px solid var(--border); cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== Product grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
.product-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: all .2s; display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.product-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.product-img {
  height: 160px; background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  display: flex; align-items: center; justify-content: center; font-size: 3.4rem;
  overflow: hidden;
}
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 12px 14px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.product-name { font-weight: 700; font-size: 1rem; line-height: 1.35; }
.product-shop { font-size: .8rem; color: var(--muted); }
.product-meta { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 8px; }
.price { font-weight: 800; color: var(--primary-dark); font-size: 1.15rem; }
.price small { font-weight: 600; font-size: .75rem; }
.rating { color: var(--star); font-size: .85rem; font-weight: 600; }
.sold-tag { font-size: .78rem; color: var(--muted); }
.stock-out {
  display: inline-block; background: #fbe9e7; color: var(--danger);
  font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px;
}

/* ===== Cards & panels ===== */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; border: 1px solid var(--border);
}
.section-title { font-size: 1.35rem; font-weight: 800; margin: 8px 0 16px; display: flex; align-items: center; gap: 8px; }
.section-title .btn { margin-left: auto; }
.empty {
  text-align: center; padding: 50px 20px; color: var(--muted);
}
.empty .big { font-size: 3rem; margin-bottom: 10px; }

/* ===== Forms ===== */
.form-page { max-width: 440px; margin: 30px auto; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 5px; font-size: .93rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; outline: none; transition: border-color .15s; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.form-error { color: var(--danger); font-size: .9rem; margin: 8px 0; min-height: 1.2em; font-weight: 600; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== Product detail ===== */
.detail { display: grid; grid-template-columns: 1fr 1.2fr; gap: 28px; }
.detail-img {
  border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 7rem;
  border: 1px solid var(--border);
}
.detail-img img { width: 100%; height: 100%; object-fit: cover; }
.detail h1 { font-size: 1.6rem; font-weight: 800; line-height: 1.3; }
.detail .price { font-size: 2rem; margin: 10px 0; display: block; }
.qty-row { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.qty-control { display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 999px; overflow: hidden; }
.qty-control button {
  width: 38px; height: 38px; border: none; background: none; font-size: 1.2rem; font-weight: 700;
  color: var(--primary);
}
.qty-control button:hover { background: var(--primary-light); }
.qty-control span { min-width: 44px; text-align: center; font-weight: 700; }
.badge {
  display: inline-block; background: var(--accent-light); color: var(--accent);
  padding: 3px 12px; border-radius: 999px; font-size: .82rem; font-weight: 700;
}

/* ===== Reviews ===== */
.review-item { border-top: 1px solid var(--border); padding: 14px 0; }
.review-item .stars { color: var(--star); }
.review-item .who { font-weight: 700; font-size: .92rem; }
.review-item .when { color: var(--muted); font-size: .78rem; }
.star-input { display: flex; gap: 4px; font-size: 1.7rem; cursor: pointer; }
.star-input span { color: #ddd; transition: color .1s; }
.star-input span.on { color: var(--star); }

/* ===== Cart ===== */
.cart-item {
  display: flex; gap: 14px; align-items: center; padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item-img {
  width: 64px; height: 64px; border-radius: 10px; overflow: hidden; flex-shrink: 0;
  background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
}
.cart-item-img img { width: 100%; height: 100%; object-fit: cover; }
.cart-item-info { flex: 1; }
.cart-item-info .name { font-weight: 700; }
.cart-summary { text-align: right; margin-top: 18px; font-size: 1.1rem; }
.cart-summary .total { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); }

/* ===== Orders ===== */
.order-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.order-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.order-id { font-weight: 800; }
.status {
  padding: 4px 14px; border-radius: 999px; font-size: .82rem; font-weight: 700;
}
.status.pending { background: #fff8e1; color: #f57f17; }
.status.confirmed { background: #e3f2fd; color: #1565c0; }
.status.shipped { background: #ede7f6; color: #6a1b9a; }
.status.completed { background: #e8f5e9; color: #2e7d32; }
.status.cancelled { background: #fbe9e7; color: var(--danger); }
.order-items { font-size: .92rem; color: var(--muted); }
.order-items li { margin-left: 20px; }
.order-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.order-total { font-weight: 800; color: var(--primary-dark); }

/* ===== Tables (dashboard) ===== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); text-align: center; border: 1px solid var(--border);
}
.stat-card .num { font-size: 1.8rem; font-weight: 800; color: var(--primary-dark); }
.stat-card .lbl { font-size: .85rem; color: var(--muted); font-weight: 600; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th {
  text-align: left; padding: 10px 12px; background: var(--primary-light);
  color: var(--primary-dark); font-weight: 700;
}
table.data th:first-child { border-radius: 8px 0 0 8px; }
table.data th:last-child { border-radius: 0 8px 8px 0; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }

/* ===== Shop page ===== */
.shop-header {
  display: flex; align-items: center; gap: 18px; background: var(--card);
  border-radius: var(--radius); padding: 22px 26px; margin-bottom: 22px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.shop-avatar {
  width: 72px; height: 72px; border-radius: 50%; background: var(--primary-light);
  display: flex; align-items: center; justify-content: center; font-size: 2.4rem; flex-shrink: 0;
}
.shop-header h1 { font-size: 1.4rem; font-weight: 800; }
.shop-header .desc { color: var(--muted); font-size: .92rem; }
.shop-card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; transition: all .2s;
}
.shop-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.shops-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

/* ===== My shop: product manage ===== */
.manage-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.manage-row:last-child { border-bottom: none; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 2px solid var(--border); }
.tab {
  padding: 9px 20px; font-weight: 700; color: var(--muted); background: none; border: none;
  border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: 1rem;
}
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ===== Guide ===== */
.guide-step {
  display: flex; gap: 16px; align-items: flex-start; background: var(--card);
  border-radius: var(--radius); padding: 20px; margin-bottom: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.guide-num {
  width: 42px; height: 42px; border-radius: 50%; background: var(--primary);
  color: #fff; font-weight: 800; font-size: 1.2rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.guide-step h3 { margin-bottom: 4px; }
.guide-step p { color: var(--muted); font-size: .93rem; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: #fff; padding: 12px 26px; border-radius: 999px;
  font-weight: 600; opacity: 0; transition: all .3s; z-index: 100; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: #2e7d32; }

/* ===== Image upload preview ===== */
.img-upload {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 14px;
  text-align: center; cursor: pointer; transition: border-color .15s; position: relative;
}
.img-upload:hover { border-color: var(--primary); }
.img-upload img { max-height: 130px; border-radius: 8px; }
.img-upload input { display: none; }
.img-upload .hint { color: var(--muted); font-size: .85rem; }

/* ===== Responsive ===== */
@media (max-width: 720px) {
  .detail { grid-template-columns: 1fr; }
  .nav { display: none; }
  .hero { padding: 26px 20px; }
  .hero h1 { font-size: 1.4rem; }
  .form-row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .product-img { height: 130px; }
}

/* ===== เฟส 1: แจ้งเตือน / กำไร / แชต ===== */
.noti-badge {
  display: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  line-height: 18px; text-align: center; vertical-align: middle;
}
.noti-badge:not(:empty) { display: inline-block; }
.noti-badge.inline { background: var(--primary); }

.margin-preview {
  display: flex; align-items: center; min-height: 42px; padding: 8px 14px;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg);
  font-weight: 700; color: var(--muted);
}
.margin-preview.gain { color: var(--accent); background: var(--accent-light); border-color: var(--accent); }
.margin-preview.loss { color: var(--danger); background: #fdecea; border-color: var(--danger); }

.order-chat {
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border);
}
.chat-log {
  display: flex; flex-direction: column; gap: 10px; max-height: 260px;
  overflow-y: auto; padding: 4px 2px 10px;
}
.chat-empty { color: var(--muted); font-size: .88rem; text-align: center; padding: 12px; }
.chat-msg { max-width: 78%; align-self: flex-start; }
.chat-msg.mine { align-self: flex-end; text-align: right; }
.chat-meta { font-size: .72rem; color: var(--muted); margin-bottom: 3px; }
.chat-bubble {
  display: inline-block; padding: 8px 13px; border-radius: 14px; font-size: .92rem;
  background: var(--card); border: 1.5px solid var(--border); text-align: left;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.mine .chat-bubble { background: var(--primary-light); border-color: var(--primary); }
.chat-input { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.chat-input textarea {
  flex: 1; resize: none; padding: 9px 12px; border: 1.5px solid var(--border);
  border-radius: 10px; font-family: inherit; font-size: .92rem; min-height: 40px;
}
.chat-input textarea:focus { outline: none; border-color: var(--primary); }

/* กล่องแจ้ง/ยินยอมการเก็บข้อมูล (PDPA) ในหน้าสมัคร */
.consent-box {
  background: var(--accent-light); border: 1.5px solid var(--accent);
  border-radius: 12px; padding: 14px 16px; margin: 4px 0 16px;
  font-size: .85rem; color: var(--text);
}
.consent-box p { margin: 6px 0; color: var(--muted); }
.consent-box ul { margin: 6px 0 10px 20px; color: var(--muted); }
.consent-box li { margin-bottom: 3px; }
.consent-check {
  display: flex; align-items: flex-start; gap: 9px; cursor: pointer;
  font-weight: 600; color: var(--text); line-height: 1.4;
}
.consent-check input { width: 18px; height: 18px; margin-top: 1px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }

/* ภาพการส่งมอบสินค้า */
.order-proof { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.proof-upload b { display: block; margin-bottom: 2px; }
.proof-upload .img-upload { display: block; }
.proof-upload button { margin-top: 10px; }
.proof-view {
  margin-top: 10px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg);
}
.proof-label { display: block; font-size: .82rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.proof-view img {
  max-width: 220px; max-height: 220px; width: auto; border-radius: 8px;
  border: 1px solid var(--border); cursor: zoom-in; display: block;
}

/* หลายรูปต่อสินค้า — ป้ายจำนวนรูป + ตัวจัดการในฟอร์ม + แกลเลอรี */
.product-img, .cart-item-img, .detail-img { position: relative; }
.img-count {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: .72rem; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}
.img-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.img-tile, .img-add {
  width: 96px; height: 96px; border-radius: 10px; overflow: hidden;
  border: 1.5px solid var(--border); position: relative; flex-shrink: 0;
}
.img-tile img { width: 100%; height: 100%; object-fit: cover; }
.cover-badge {
  position: absolute; left: 4px; top: 4px; background: var(--primary); color: #fff;
  font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px;
}
.img-remove {
  position: absolute; right: 3px; top: 3px; width: 22px; height: 22px;
  border: none; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff;
  font-size: .8rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.img-add {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--muted); font-size: .82rem; font-weight: 600; text-align: center;
  border-style: dashed; background: var(--bg);
}
.img-add:hover { border-color: var(--primary); color: var(--primary); }
.img-add input { display: none; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gthumb {
  width: 60px; height: 60px; border-radius: 8px; overflow: hidden; padding: 0;
  border: 2px solid var(--border); cursor: pointer; background: none;
}
.gthumb.active { border-color: var(--primary); }
.gthumb img { width: 100%; height: 100%; object-fit: cover; }

.pr-saved { margin-left: 10px; color: var(--accent); font-weight: 600; font-size: .88rem; }
