/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  --green:   #5ba85a;
  --red:     #e53935;
  --dark:    #1a1a1a;
  --gray-h:  #8c8c8c;
  --gray-bg: #f5f5f5;
  --gray-bd: #e0e0e0;
  --star:    #f5a623;
  --id-bg:   #2a2a2a;
  --radius:  10px;
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ป้องกันรูปทุกตัว overflow container */
img { max-width: 100%; height: auto; display: block; }

/* ล็อค horizontal scroll ทั้งหน้า */
html { overflow-x: hidden; }
body { overflow-x: hidden; width: 100%; }

/* ============================================================
   Base — Mobile (375px iPhone X target)
   ============================================================ */
body {
  font-family: 'Sarabun', 'Noto Sans Thai', sans-serif;
  background: var(--gray-bg);
  color: #333;
  font-size: 14px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ── Container ── */
.qr-container {
  width: 100%;
  max-width: 100vw;   /* ห้ามเกิน viewport */
  padding: 10px;
  overflow: hidden;
}

/* ── Header ── */
.qr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 3px solid var(--green);
  border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.qr-header__brand  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.qr-header__logo   { width: 34px; height: 34px; flex-shrink: 0; }
.qr-header__text   { display: flex; flex-direction: column; min-width: 0; }
.qr-header__title  { font-size: 14px; font-weight: 700; color: #1a1a1a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-header__subtitle { font-size: 10px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-header__id {
  flex-shrink: 0;
  background: var(--id-bg);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Card ── */
.card {
  background: #fff;
  border: 1px solid var(--gray-bd);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  /* ป้องกัน card ขยายเกิน parent */
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.card__header {
  background: var(--gray-h);
  color: #fff;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card__header i { margin-right: 5px; }

.card__body        { padding: 12px; }
.card__body--nopad { padding: 0; }
.card__body--inner { padding: 12px; }

/* ============================================================
   Card Modifiers — แต่ละ card มี style เป็นของตัวเอง
   ============================================================ */

/* ── ข่าวประชาสัมพันธ์ ── */
.card--news .card__header {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

/* ── รายละเอียดผลิตภัณฑ์ ── */
.card--product .card__header {
  background: var(--green);
}

/* ── ข้อมูลใบอนุญาต ── */
.card--license .card__header {
  background: var(--red);
}

/* ── ข้อมูลผู้ผลิตและนำเข้า ── */
.card--trader .card__header {
  background: #374151;
}

/* ── ภาพถ่ายผลิตภัณฑ์ / Carousel ── */
.card--carousel .card__header {
  background: #1e3a5f;
}

/*
  ════════════════════════════════════════════════
  CAROUSEL CARD — Layout Template
  ════════════════════════════════════════════════

  card (width:100%, overflow:hidden)
  └─ card__body (width:100%, padding:0)
     ├─ model-tabs   (overflow-x:auto, flex nowrap)
     ├─ model-carousel (overflow:hidden, width:100%)
     │  └─ track (display:flex, width:100%)   ← width:100% สำคัญ: ทำให้ JS translateX(-n*100%) = n×card-width
     │     └─ slide × N (min-width:100%, flex-shrink:0)
     │        └─ img-main-wrap (width:min(300px,100%), aspect-ratio:6/7)
     └─ dots / old-photos
  ════════════════════════════════════════════════
*/

.card--carousel {
  contain: inline-size;
  overflow: hidden;
}

/* ── Tabs ── */
.card--carousel .model-tabs {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
}

/* ── Carousel wrapper: clip slides ที่ซ่อน ── */
.card--carousel .model-carousel {
  overflow: hidden;
  width: 100%;
}

/* track: width:100% → translateX(-n×100%) เท่ากับ n×card-width */
.card--carousel .model-carousel__track {
  width: 100%;
}

/* slide: เต็ม carousel, overflow:hidden ป้องกัน content ล้น */
.card--carousel .model-carousel__slide {
  min-width: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

/*
  รูปภาพ:
  · max-width: 300px          → ไม่เกิน 300px
  · width: 100%               → fluid ตาม slide
  · height: clamp(...)        → ไม่เล็กเกิน 200px ไม่ใหญ่เกิน 350px ปรับตาม viewport
  · margin: 0 auto            → center กลาง slide เสมอ
  · overflow: hidden          → รูปต้องไม่ล้น box นี้
*/
.card--carousel .img-main-wrap {
  width: min(300px, 100%);
  aspect-ratio: 6/7;
  height: unset;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 6px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* <a> ที่หุ้มรูปต้องเต็ม wrap */
.card--carousel .img-main-wrap > a {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

/* รูปภาพ: เต็ม wrap, ไม่ crop */
.card--carousel .img-main {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ── Global img-main-wrap: โครงสร้างพื้นฐาน ── */
.img-main-wrap {
  border-radius: 6px;
  overflow: hidden;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── การประเมินและร้องเรียน ── */
.card--rating .card__header {
  background: #7c3aed;
}

/* ── ข้อแนะนำ / Infographic ── */
.card--infographic .card__header {
  background: #0369a1;
}
.card--infographic .card__body {
  padding: 16px;
}

/* ── Layout — mobile: col-left/col-right transparent, cards order via CSS ── */
.page-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

/* col wrappers โปร่งใสบน mobile → children เข้า grid โดยตรง */
.col-left,
.col-right { display: contents; }

/* mobile order */
.card--license  { order: 1; }
.card--trader   { order: 2; }
.card--product  { order: 3; }
.card--carousel { order: 4; }
.card--rating   { order: 5; }

/* ── Info Rows — stacked on mobile ── */
.product-title {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 10px;
}

.info-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-bd);
}

.info-row:last-child { border-bottom: none; }

.info-row__label {
  font-weight: 600;
  color: #888;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.info-row__value {
  color: #1a1a1a;
  font-size: 14px;
}

.info-row__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-row__list li {
  color: #1a1a1a;
  font-size: 14px;
  padding-left: 14px;
  position: relative;
}

.info-row__list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: #888;
}

.trader-name {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 10px;
}

/* ── License Items ── */
.license-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-bd);
}

.license-item:last-child { border-bottom: none; }

.license-item__pdf {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--red);
  color: #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.license-item__info { flex: 1; min-width: 0; }

.license-item__link {
  color: var(--red);
  font-weight: 700;
  text-decoration: none;
  font-size: 0.9rem;
  display: block;
  word-break: break-all;
}

.license-item__link:hover { text-decoration: underline; }

.license-item__status {
  font-size: 0.78rem;
  font-weight: 600;
  display: block;
  margin-top: 2px;
}

.license-item__tis {
  font-size: 0.78rem;
  color: #666;
  margin-top: 3px;
  line-height: 1.4;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity .2s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.97); opacity: .9; }

.btn--outline {
  border: 2px solid var(--green);
  color: var(--green);
  background: transparent;
}

.btn--dark   { background: var(--dark); color: #fff; }
.btn--red    { background: var(--red);  color: #fff; }

.btn--upload {
  background: #f0f4ff;
  border: 1.5px solid #c7d2fe;
  color: #3730a3;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 6px;
  width: 100%;          /* full-width on mobile */
  justify-content: center;
}

/* ── Status Alerts ── */
.status-alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.status-alert--danger  { background: #fee2e2; border-left: 4px solid var(--red);   color: #991b1b; }
.status-alert--warning { background: #fef3c7; border-left: 4px solid #f59e0b; color: #92400e; }

/* ── Model Tabs — horizontal scroll on mobile ── */
.model-tabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-bd);
  /* ห้าม container ขยายเกิน card */
  min-width: 0;
  width: 100%;
}

.model-tabs::-webkit-scrollbar { display: none; }

.model-tab-pill {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--gray-bd);
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  /* จำกัดความกว้าง pill ไม่ให้เกิน 70% viewport */
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-tab-pill.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ── Carousel ── */
.model-carousel {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  width: 100%;
}

.model-carousel__track {
  display: flex;
  transition: transform .38s cubic-bezier(.4,0,.2,1);
  width: 100%;    /* ทำให้ JS translateX(-n×100%) = n×carousel-width */
}

.model-carousel__slide {
  min-width: 100%;   /* 100% ของ .model-carousel */
  flex-shrink: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
}

/* ── Product Image (base — ขนาดจริงอยู่ใน .card--carousel .img-main-wrap) ── */

/* link ที่หุ้มรูปต้องเต็ม wrap */
.img-main-wrap > a {
  display: flex;
  width: 100%;
  height: 100%;
}

.img-main {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity .2s;
}

.img-placeholder {
  color: #ccc;
  font-size: 2.2rem;
  text-align: center;
  padding: 30px;
}

/* ── Thumbnail ── */
.img-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color .15s;
}

.img-thumb.active { border-color: var(--green); }

/* ── Slide labels ── */
.slide-model-name {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  text-align: center;
  line-height: 1.4;
}

.slide-upload { text-align: center; width: 100%; }

.upload-filename {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
  display: none;
  word-break: break-all;
  text-align: center;
}

/* ── Arrow Buttons — ซ่อนบน mobile (ใช้ swipe แทน) ── */
.arrow-btn {
  display: none;        /* hidden on mobile */
}

.arrow-btn.hidden { display: none; }

/* ── Dots ── */
.model-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 0 12px;
}

.model-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ccc;
  cursor: pointer;
  transition: background .2s, transform .2s;
}

.model-dot.active { background: var(--green); transform: scale(1.35); }

/* ── Counter Badge ── */
.model-counter {
  background: rgba(0,0,0,.25);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
}

/* ── Star Rating — quick bar ── */
.star-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  font-size: 1.8rem;
  cursor: pointer;
  padding: 6px 0;
}

.star { color: #ddd; transition: color .15s; }
.star.filled { color: var(--star); }

/* ── Star Rating — modal form ── */
.rating-item { margin-bottom: 14px; }
.rating-item__label { font-weight: 600; margin-bottom: 5px; font-size: 13px; }

.starrating {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 4px;
}

.starrating input { display: none; }

.starrating label {
  font-size: 1.7rem;
  line-height: 1;
  color: #ddd;
  cursor: pointer;
  transition: color .15s;
}

.starrating label:hover,
.starrating label:hover ~ label,
.starrating input:checked ~ label {
  color: var(--star);
}

/* ── Image Gallery (old photos) ── */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.img-gallery__item { border-radius: 6px; overflow: hidden; }
.img-gallery__item img { width: 100%; height: 130px; object-fit: cover; display: block; }
.img-gallery__caption { padding: 5px 6px; font-size: 11px; color: #666; }

/* ── Infographic ── */
.infographic-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.infographic-item { border-radius: 8px; overflow: hidden; }
.infographic-item img { width: 100%; height: auto; display: block; }

/* ── News ── */
.news-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-bd);
  align-items: flex-start;
}

.news-item:last-child { border-bottom: none; }
.news-item__icon  { color: #f59e0b; font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }
.news-item__title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.news-item__detail { font-size: 12px; color: #666; }
.news-item__link  { font-size: 12px; color: var(--green); font-weight: 600; text-decoration: none; margin-top: 3px; display: inline-block; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;      /* bottom-sheet on mobile */
  justify-content: center;
  padding: 0;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal-box {
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 -4px 30px rgba(0,0,0,.2);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}

.modal-backdrop.open .modal-box { transform: translateY(0); }

.modal-box__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-bd);
  font-weight: 700;
  font-size: 15px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.modal-box__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #888;
  line-height: 1;
  padding: 0 4px;
  -webkit-tap-highlight-color: transparent;
}

.modal-box__close:hover { color: #333; }
.modal-box__body { padding: 16px; }

/* ── Barcode overflow safe ── */
.barcode-box { overflow: hidden; }
.barcode-box svg { max-width: 100%; height: auto; }

/* ============================================================
   sm: 480px+  (large phones / small landscape)
   ============================================================ */
@media (min-width: 480px) {
  body { font-size: 15px; }

  .qr-container { padding: 12px; }

  .qr-header__logo     { width: 38px; height: 38px; }
  .qr-header__title    { font-size: 15px; }
  .qr-header__subtitle { font-size: 11px; }
  .qr-header__id       { font-size: 11px; }

  .card__body        { padding: 14px; }
  .card__body--inner { padding: 14px; }
  .card__header      { font-size: 14px; padding: 9px 14px; }

  .img-thumb      { width: 54px; height: 54px; }
  .img-gallery    { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .img-gallery__item img { height: 150px; }

  .model-tab-pill { font-size: 13px; padding: 4px 12px; max-width: 180px; }
  .model-tabs     { gap: 6px; }

  .infographic-gallery { grid-template-columns: repeat(2, 1fr); }

  .product-title { font-size: 17px; }
  .trader-name   { font-size: 16px; }

  /* info-row: side-by-side at 480px+ */
  .info-row { flex-direction: row; gap: 8px; align-items: baseline; }
  .info-row--list { align-items: flex-start; }
  .info-row__label { flex: 0 0 120px; font-size: 13px; text-transform: none; letter-spacing: 0; color: #555; font-weight: 600; }
  .info-row__value { flex: 1; font-size: 14px; }
  .info-row__list { flex: 1; }

  .star-row { font-size: 2rem; }
}

/* ============================================================
   md: 768px+  (tablet / landscape phone)
   ============================================================ */
@media (min-width: 768px) {
  .qr-container { padding: 16px; max-width: 1040px; margin: 0 auto; }

  .qr-header { padding: 12px 16px; }
  .qr-header__logo     { width: 40px; height: 40px; }
  .qr-header__title    { font-size: 1.05rem; }
  .qr-header__subtitle { font-size: 0.75rem; }
  .qr-header__id       { font-size: 0.75rem; padding: 4px 10px; }

  .card__body        { padding: 20px; }
  .card__body--inner { padding: 16px 16px 20px; }
  .card__header      { font-size: 0.95rem; padding: 10px 16px; }
  .card { margin-bottom: 16px; }

  /* 2-column layout — flex ทำให้แต่ละ column สูงอิสระ ไม่แชร์ row height */
  .page-wrap {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    max-width: 1040px;
    margin: 0 auto 24px;
  }

  .col-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 62;
    min-width: 0;
  }

  .col-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 38;
    min-width: 0;
  }

  /* reset mobile order */
  .card--license,
  .card--trader,
  .card--product,
  .card--carousel,
  .card--rating { order: 0; }

  .product-title { font-size: 1.3rem; margin-bottom: 12px; }
  .trader-name   { font-size: 1.05rem; margin-bottom: 12px; }

  .info-row__label { flex: 0 0 140px; font-size: 0.88rem; }
  .info-row__value { font-size: 15px; }

  .img-thumb      { width: 64px; height: 64px; }
  .img-gallery    { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .img-gallery__item img { height: 160px; }

  .model-tab-pill { font-size: 0.8rem; padding: 4px 14px; }

  /* Arrow buttons แสดงบน tablet+ */
  .arrow-btn {
    display: flex;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.92);
    border: 1px solid var(--gray-bd);
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
    cursor: pointer;
    font-size: 1.3rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    z-index: 2;
    color: #333;
    transition: background .2s;
  }
  .arrow-btn:hover   { background: #fff; }
  .arrow-btn--left   { left: 6px; }
  .arrow-btn--right  { right: 6px; }
  .arrow-btn.hidden  { display: none; }

  /* Upload button คืน auto-width */
  .btn--upload { width: auto; }

  /* slide upload เต็มแถว */
  .slide-upload { width: 100%; }

  .infographic-gallery { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

  /* Modal: centered dialog on tablet+ */
  .modal-backdrop { align-items: center; padding: 16px; }
  .modal-box {
    border-radius: var(--radius);
    max-width: 480px;
    transform: translateY(20px);
  }
  .modal-backdrop.open .modal-box { transform: translateY(0); }
}

/* ============================================================
   lg: 1024px+  (desktop)
   ============================================================ */
@media (min-width: 1024px) {
  body { font-size: 15px; }



  .qr-header__title    { font-size: 1.1rem; }
  .qr-header__subtitle { font-size: 0.8rem; }

  .model-tab-pill:hover:not(.active) { border-color: var(--green); color: var(--green); }
  .btn:hover { opacity: .88; }
  .btn--outline:hover { background: var(--green); color: #fff; }

  .img-gallery { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .img-gallery__item img { height: 180px; }
}
