/* Sukree Sales Catalog — tablet-first */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --blue: #1565c0;
  --blue-d: #0d47a1;
  --green: #2e7d32;
  --red: #c62828;
  --amber: #ef6c00;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e3e8ef;
  --txt: #1e293b;
  --mut: #64748b;
  --r: 14px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif;
  background: var(--bg); color: var(--txt); font-size: 15px;
}
.hidden { display: none !important; }

/* ── Login ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--blue-d), var(--blue) 60%, #42a5f5);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 36px 30px; width: 100%;
  max-width: 380px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { font-size: 52px; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; color: var(--blue-d); }
.login-sub { color: var(--mut); font-size: 13px; margin: 6px 0 22px; }
.login-card input {
  width: 100%; padding: 13px 15px; margin-bottom: 12px; font-size: 16px;
  border: 1.5px solid var(--line); border-radius: 10px; outline: none;
}
.login-card input:focus { border-color: var(--blue); }
.btn-primary {
  width: 100%; padding: 13px; font-size: 16px; font-weight: 600; color: #fff;
  background: var(--blue); border: 0; border-radius: 10px; cursor: pointer;
}
.btn-primary:active { background: var(--blue-d); }
.login-err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 30; background: #fff;
  border-bottom: 1px solid var(--line); padding: 10px 14px 8px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 18px; font-weight: 700; color: var(--blue-d); white-space: nowrap; }
.search-box { flex: 1; }
.search-box input {
  width: 100%; padding: 10px 16px; font-size: 15px; border: 1.5px solid var(--line);
  border-radius: 24px; outline: none; background: var(--bg);
}
.search-box input:focus { border-color: var(--blue); background: #fff; }
.btn-icon {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; font-size: 17px; cursor: pointer; color: var(--mut); flex: none;
}

/* ── Chips ── */
.chip-row {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 4px;
  scrollbar-width: none; cursor: grab; user-select: none;
}
.chip-row:active { cursor: grabbing; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 16px; border-radius: 20px; background: var(--bg); color: var(--txt);
  border: 1px solid var(--line); font-size: 14px; white-space: nowrap; cursor: pointer;
  flex: none;
}
.chip .n { color: var(--mut); font-size: 12px; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip.on .n { color: #bbdefb; }

/* ── Filter row ── */
.filter-row { display: flex; align-items: center; gap: 14px; padding-top: 8px; }
.filter-row select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--txt);
}
.filter-circles { display: flex; gap: 16px; overflow-x: auto; padding: 10px 2px 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filter-circles::-webkit-scrollbar { display: none; }
.filter-circle { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: none; border: 0; cursor: pointer; padding: 0; }
.filter-circle .fc-ic { width: 46px; height: 46px; border-radius: 50%; background: var(--bg);
  border: 2px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-size: 20px; transition: background .15s, border-color .15s, box-shadow .15s, transform .15s; }
.filter-circle .fc-label { font-size: 11px; font-weight: 600; color: var(--mut); white-space: nowrap; }
.filter-circle:active .fc-ic { transform: scale(.92); }
.filter-circle.on .fc-ic { background: linear-gradient(135deg, var(--amber), var(--red)); border-color: transparent;
  box-shadow: 0 3px 10px rgba(198,40,40,.4); }
.filter-circle.on .fc-label { color: var(--red); font-weight: 700; }
.result-count { margin-left: auto; font-size: 13px; color: var(--mut); }

/* ── Grid ── */
main { padding: 14px; max-width: 1400px; margin: 0 auto; }
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}
.card {
  background: var(--card); border-radius: var(--r); overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); transition: transform .1s;
  display: flex; flex-direction: column;
}
.card:active { transform: scale(.97); }
.card-img {
  position: relative; aspect-ratio: 1; background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.card-img img { width: 100%; height: 100%; object-fit: contain; }
.card-img .noimg { font-size: 42px; opacity: .18; }
.badge-wrap {
  position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column;
  gap: 4px; max-width: 92%; align-items: flex-start;
}
.badge-deal, .badge-promo {
  color: #fff; font-size: 12px; font-weight: 600; padding: 4px 10px;
  border-radius: 14px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge-deal  { background: var(--red);   box-shadow: 0 2px 8px rgba(198,40,40,.4); }
.badge-promo { background: var(--amber); box-shadow: 0 2px 8px rgba(239,108,0,.4); }

/* ── Sale card (โปรโมชั่น) ── */
.sale-ribbon {
  position: absolute; top: 10px; left: 0; display: flex; align-items: center; gap: 5px;
  padding: 6px 16px 6px 12px; clip-path: polygon(0 0, 100% 0, 88% 50%, 100% 100%, 0 100%);
  box-shadow: 0 3px 8px rgba(0,0,0,.3); z-index: 3; animation: ribbonShine 2.4s ease-in-out infinite;
}
.sale-ribbon.sale  { background: linear-gradient(135deg, #ffca28, var(--red)); }
.sale-ribbon.flash { background: linear-gradient(135deg, #4a148c, #7b1fa2 55%, var(--red)); }
.sale-ribbon .lbl { font-weight: 800; font-style: italic; font-size: 14.5px; letter-spacing: .5px;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.35); white-space: nowrap; }
.sale-ribbon .ic { font-size: 14px; }
@keyframes ribbonShine { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.08); } }
.sale-date {
  position: absolute; top: 56px; left: 8px; background: #fff; color: var(--red);
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); white-space: nowrap; z-index: 3;
}
.sale-code {
  position: absolute; top: 10px; right: 10px; background: #fff; color: var(--blue-d);
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); z-index: 3;
}
.sale-price-bubble {
  position: absolute; bottom: 6px; right: 6px; width: 76px; height: 76px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e53935, var(--red)); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 12px rgba(198,40,40,.4); z-index: 3; text-align: center; padding: 4px 6px;
}
.sale-price-bubble .p { font-size: 17px; font-weight: 800; line-height: 1.15; white-space: nowrap; color: #ffeb3b; }
.sale-price-bubble .u { font-size: 9.5px; font-weight: 500; opacity: .9; white-space: nowrap; }
.sale-cta {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(30,41,59,.38); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  color: #fff; font-size: 13px; font-weight: 600;
  padding: 7px 22px; border-radius: 20px; z-index: 3; white-space: nowrap;
}
#top10-grid { grid-template-columns: repeat(5, 1fr); }
.card.sale-card .badge-best { top: 46px; }

.avg-price { font-size: 12.5px; color: var(--green); font-weight: 600; }
.deal-avg  { font-size: 13px; margin-top: 4px; color: var(--green); }

.promo-box {
  border: 1px solid #ffe0b2; background: #fff8f0; border-radius: 10px;
  padding: 10px 12px; margin-top: 8px;
}
.promo-head { font-weight: 700; font-size: 14px; color: var(--amber); }
.promo-until { font-weight: 400; font-size: 12px; color: var(--mut); margin-left: 8px; }
.promo-line { font-size: 13.5px; margin-top: 4px; }
.promo-line.avg { color: var(--green); font-weight: 700; }

/* ── ของแถม (สไตล์ banner: รูป + ฟรี!) ── */
.gift-row {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
  background: #fff; border: 1px dashed #ffb74d; border-radius: 10px; padding: 8px 10px;
}
.gift-img, .gift-noimg {
  width: 56px; height: 56px; border-radius: 8px; object-fit: contain;
  background: #fff; border: 1px solid var(--line); flex: none;
}
.gift-noimg { display: flex; align-items: center; justify-content: center; font-size: 26px; }
.gift-info { min-width: 0; }
.gift-free { font-size: 14px; font-weight: 700; color: var(--red); }
.gift-qty  { color: var(--txt); font-weight: 600; }
.gift-when { font-size: 12.5px; color: var(--mut); margin-top: 2px; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-name {
  font-size: 16px; line-height: 1.35; font-weight: 600; min-height: 44px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-code { font-size: 12px; color: var(--mut); }
.card-foot { display: flex; align-items: flex-end; justify-content: space-between; margin-top: auto; }
.card-price { font-size: 18px; font-weight: 700; color: var(--blue-d); }
.card-price .cur { font-size: 12px; font-weight: 400; color: var(--mut); }
.stock { font-size: 12px; font-weight: 600; }
.stock.in  { color: var(--green); }
.stock.low { color: var(--amber); }
.stock.out { color: var(--mut); }

.sentinel { height: 60px; }
.empty { text-align: center; color: var(--mut); padding: 60px 0; font-size: 16px; }

/* ── Detail overlay ── */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.detail-card {
  background: #fff; border-radius: 20px; width: 100%; max-width: 760px;
  max-height: 92vh; overflow-y: auto; position: relative; padding: 22px;
}
.detail-close {
  position: absolute; top: 14px; right: 14px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--bg); font-size: 16px; cursor: pointer; color: var(--mut);
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-img {
  aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.detail-img img { width: 100%; height: 100%; object-fit: contain; }
.detail-img .noimg { font-size: 72px; opacity: .15; }
.detail-info h2 { font-size: 20px; line-height: 1.4; margin-bottom: 4px; }
.detail-name-en { font-size: 14px; color: var(--mut); margin-bottom: 4px; }
.detail-meta { font-size: 13px; color: var(--mut); margin-bottom: 12px; }
.detail-meta .generic { color: var(--blue-d); font-weight: 600; }
.detail-deal {
  background: #ffebee; color: var(--red); font-weight: 700; padding: 10px 14px;
  border-radius: 10px; margin-bottom: 12px; font-size: 15px;
}
.detail-price-main { font-size: 30px; font-weight: 800; color: var(--blue-d); }
.detail-price-main .cur { font-size: 14px; font-weight: 400; color: var(--mut); }
.detail-stock { margin: 10px 0 16px; font-size: 15px; font-weight: 600; }
.price-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.price-table th {
  text-align: left; color: var(--mut); font-weight: 500; font-size: 12px;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.price-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.price-table td.pr { font-weight: 700; color: var(--blue-d); text-align: right; }
.sec-title { font-size: 13px; color: var(--mut); font-weight: 600; margin-top: 14px; }
.last-sale { font-size: 12.5px; color: var(--mut); margin-top: 10px; }

/* ── Lightbox (ขยายรูป) ── */
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(10,15,25,.88);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
  padding: 20px;
}
.lightbox img {
  max-width: 96%; max-height: 96%; object-fit: contain; border-radius: 12px;
  background: #fff; box-shadow: 0 10px 50px rgba(0,0,0,.5);
}
.detail-img img, .gift-img { cursor: zoom-in; }

/* ── Customer Application (เปิดบัญชีลูกค้า) ── */
.ca-card { max-width: 680px; }
.ca-title { font-size: 19px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ca-sec {
  font-size: 14px; font-weight: 700; color: var(--blue-d); margin: 18px 0 8px;
  padding-bottom: 5px; border-bottom: 2px solid #e3f0fd;
}
.ca-fld { display: block; margin-bottom: 10px; }
.ca-fld span { display: block; font-size: 12.5px; color: var(--mut); margin-bottom: 4px; }
.ca-fld input, .ca-fld select, .ca-fld textarea {
  width: 100%; padding: 10px 12px; font-size: 15px; border: 1.5px solid var(--line);
  border-radius: 9px; outline: none; font-family: inherit; background: #fff;
}
.ca-fld input:focus, .ca-fld textarea:focus { border-color: var(--blue); }
.ca-chk { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 8px 0 12px; }
.ca-chk input { width: 17px; height: 17px; }
.ca-hint { font-size: 12.5px; color: var(--mut); background: var(--bg);
  padding: 8px 12px; border-radius: 8px; margin: 6px 0; }
.ca-actions { display: flex; gap: 10px; margin-top: 16px; }
.ca-actions .btn-primary { width: auto; padding: 11px 22px; }
.ca-btn-ghost { padding: 11px 18px; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; font-size: 15px; cursor: pointer; color: var(--txt); }
.ca-row { position: relative; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer; background: #fff; }
.ca-row:active { background: var(--bg); }
.ca-row-main { font-size: 15px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ca-no { font-size: 12px; color: var(--mut); }
.ca-row-sub { font-size: 12.5px; color: var(--mut); margin-top: 4px; }
.ca-st { position: absolute; top: 12px; right: 12px; font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 12px; }
.ca-title .ca-st { position: static; }
.ca-st-pending { background: #fff3e0; color: var(--amber); }
.ca-st-ok      { background: #e8f5e9; color: var(--green); }
.ca-st-no      { background: #ffebee; color: var(--red); }
.ca-info { display: flex; gap: 10px; font-size: 14px; padding: 5px 0;
  border-bottom: 1px dashed var(--line); }
.ca-info span { color: var(--mut); font-size: 12.5px; min-width: 110px; flex: none; padding-top: 1px; }
.ca-file { font-size: 13.5px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.ca-file a { color: var(--blue-d); }
.ca-file-del { border: 1px solid var(--line); background: #fff; color: var(--red);
  border-radius: 6px; padding: 2px 10px; font-size: 12px; cursor: pointer; margin-left: 8px; }
.ca-upload { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ca-upload select, .ca-upload input[type=file] {
  padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 9px; font-size: 13.5px;
  background: #fff; max-width: 100%;
}

/* ── Signature pad + slots ── */
.sign-card {
  background: #fff; border-radius: 18px; padding: 20px; width: 100%; max-width: 680px;
}
.sign-title { font-size: 16px; font-weight: 700; color: var(--blue-d); margin-bottom: 12px; }
#sign-canvas {
  width: 100%; height: 220px; border: 2px dashed var(--line); border-radius: 12px;
  touch-action: none; background: #fff; cursor: crosshair;
}
.sig-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.sig-slot { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; text-align: center; }
.sig-slot-label { font-size: 12.5px; color: var(--mut); margin-bottom: 8px; }
.sig-slot-ok { color: var(--green); font-weight: 700; font-size: 13.5px; }
.sig-slot-wait { color: var(--mut); font-size: 13px; }

/* ── B2B Order Board (Kanban) ── */
.so-wide { max-width: 1360px !important; width: 96vw; }
.kb-wrap { overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.kb { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 10px;
      min-width: 1240px; }
@media (max-width: 700px) { .kb { min-width: 1240px; } }  /* mobile: ปัดซ้ายขวา */
.kb-col { background: var(--bg); border-radius: 12px; display: flex; flex-direction: column;
          max-height: 62vh; }
.kb-head { padding: 9px 12px; border-radius: 12px 12px 0 0; color: #fff; font-weight: 700;
           font-size: 13.5px; display: flex; justify-content: space-between; align-items: center;
           position: sticky; top: 0; }
.kb-head .n { background: rgba(255,255,255,.28); border-radius: 10px; padding: 1px 9px;
              font-size: 12px; }
.kb-head.st-NEW       { background: #ef6c00; }
.kb-head.st-CONFIRMED { background: #1565c0; }
.kb-head.st-PICKING   { background: #6a1b9a; }
.kb-head.st-PACKED    { background: #00838f; }
.kb-head.st-SHIPPED   { background: #283593; }
.kb-head.st-DELIVERED { background: #2e7d32; }
.kb-body { padding: 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.kb-card { background: #fff; border: 1px solid var(--line); border-radius: 10px;
           padding: 9px 11px; cursor: pointer; box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.kb-card:active { transform: scale(.97); }
.kb-no { font-weight: 700; font-size: 13px; color: var(--blue-d); }
.kb-cust { font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis;
           white-space: nowrap; }
.kb-sub { font-size: 11.5px; color: var(--mut); margin-top: 3px; display: flex;
          justify-content: space-between; }
.kb-amt { font-weight: 700; color: var(--txt); }
.kb-empty { text-align: center; color: var(--mut); font-size: 12px; padding: 16px 0; }
.kb-cancel-note { font-size: 12px; color: var(--mut); margin-top: 8px; }
.kb-cancel-note a { color: var(--red); cursor: pointer; }

/* ── Compact list grid (รองรับข้อมูลเยอะ) ── */
.so-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
           gap: 10px; max-height: 62vh; overflow-y: auto; padding: 2px; }
.so-grid .ca-row { margin-bottom: 0; padding: 10px 12px; }
.so-grid .ca-row-main { font-size: 13.5px; }
.so-grid .ca-row-sub { font-size: 11.5px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 12px 22px; border-radius: 24px;
  font-size: 14px; z-index: 99; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}

/* skeleton */
.skel { background: linear-gradient(90deg,#eef1f5 25%,#f7f9fb 50%,#eef1f5 75%);
  background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: var(--r); height: 280px; }
@keyframes sh { to { background-position: -200% 0; } }

/* ── Top 10 สินค้าขายดี ── */
.top10-sub { color: var(--mut); font-size: 13.5px; margin: 4px 0 16px; }
/* หมายเหตุ: .rank-badge ใช้ "ภายใน" .badge-wrap เดิม (ไม่ absolute เอง) กันชนกับ badge โปรฯ มุมเดียวกัน */
.rank-badge {
  background: var(--blue-d); color: #fff; font-weight: 700; font-size: 12px;
  padding: 4px 10px; border-radius: 14px; align-self: flex-start;
}
.badge-best {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  display: flex; align-items: center; gap: 3px;
  background: linear-gradient(135deg, var(--amber), var(--red)); color: #fff;
  font-weight: 700; font-size: 12px; padding: 4px 10px 4px 6px; border-radius: 14px;
  box-shadow: 0 2px 8px rgba(198,40,40,.4);
  animation: badgePulse 1.8s ease-in-out infinite;
}
.badge-best .flame { animation: flameFlicker 1s ease-in-out infinite; display:inline-block; }
@keyframes badgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(198,40,40,.4), 0 0 0 0 rgba(239,108,0,.5); }
  50% { transform: scale(1.07); box-shadow: 0 2px 10px rgba(198,40,40,.45), 0 0 0 7px rgba(239,108,0,0); }
}
@keyframes flameFlicker {
  0%, 100% { transform: scale(1) rotate(-2deg); }
  30% { transform: scale(1.1) rotate(2deg); }
  60% { transform: scale(.95) rotate(-3deg); }
}
/* นาทีทอง ราคาพิเศษ */
.flash-box {
  border-radius: 12px; padding: 14px 16px; margin-top: 10px; color: #fff;
  background: linear-gradient(135deg, #4a148c, #7b1fa2 55%, var(--red));
  box-shadow: 0 6px 20px rgba(123,31,162,.35);
}
.flash-price { font-size: 26px; font-weight: 800; }
.flash-orig { font-size: 15px; text-decoration: line-through; opacity: .7; margin-left: 10px; }
.flash-window {
  font-size: 12.5px; margin-top: 8px; display: inline-block;
  background: rgba(255,255,255,.18); padding: 4px 10px; border-radius: 10px;
}
