/* =============================================================================
   afs-lists.css — Plant/Fruit theme compatible
   ปรับแต่ง: override ตัวแปรด้านล่างใน style.css ของ theme ได้เลย
   ============================================================================= */

/* ── CSS Variables (ปรับแต่งได้) ────────────────────────────────────────────── */
:root {
  /* สีหลัก */
  --afsl-primary: #2e7d32;
  --afsl-primary-dark: #1b5e20;
  --afsl-accent: #ff6f00;
  --afsl-accent-hover: #e65100;

  /* อันดับ */
  --afsl-gold: #f9a825;
  --afsl-silver: #90a4ae;
  --afsl-bronze: #a1887f;

  /* ตัวอักษร / พื้นหลัง */
  --afsl-text: #333;
  --afsl-muted: #777;
  --afsl-border: #e0e0e0;
  --afsl-bg: #fafafa;
  --afsl-row-hover-bg: #f1f8e9;

  /* source badge */
  --afsl-shopee-bg: #ee4d2d;
  --afsl-shopee-color: #fff;
  --afsl-lazada-bg: #0f0f96;
  --afsl-lazada-color: #fff;

  /* รูปแบบ */
  --afsl-radius: 8px;
  --afsl-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --afsl-font-size: 14px;

  /* ปุ่ม */
  --afsl-btn-bg: #ff6f00;
  --afsl-btn-color: #fff;
  --afsl-btn-hover-bg: #e65100;
  --afsl-btn-radius: 6px;
  --afsl-btn-font-size: 13px;
}

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.afsl-filter-bar {
  background: var(--afsl-bg);
  border: 1px solid var(--afsl-border);
  border-radius: var(--afsl-radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.afsl-filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.afsl-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 180px;
}

.afsl-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--afsl-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.afsl-select {
  border: 1px solid var(--afsl-border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: var(--afsl-font-size);
  background: #fff;
  color: var(--afsl-text);
  cursor: pointer;
  width: 100%;
}

.afsl-select:focus {
  outline: none;
  border-color: var(--afsl-primary);
  box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.15);
}

.afsl-btn-filter,
.afsl-btn-reset {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: var(--afsl-font-size);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  align-self: flex-end;
}

.afsl-btn-filter {
  background: var(--afsl-primary);
  color: #fff;
  border: none;
}
.afsl-btn-filter:hover {
  background: var(--afsl-primary-dark);
}

.afsl-btn-reset {
  background: transparent;
  color: var(--afsl-muted);
  border: 1px solid var(--afsl-border);
}
.afsl-btn-reset:hover {
  background: #f5f5f5;
  color: var(--afsl-text);
}

.afsl-hidden {
  display: none !important;
}

.afsl-hint {
  text-align: center;
  color: var(--afsl-muted);
  padding: 40px 0;
  font-size: 15px;
}

/* ── Source checkbox filter ──────────────────────────────────────────────────── */
.afsl-source-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 16px;
  background: #fff;
  border: 1px solid var(--afsl-border);
  border-radius: var(--afsl-radius);
}

.afsl-source-filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--afsl-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.afsl-cb-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--afsl-border);
  background: #fafafa;
  font-size: 13px;
  font-weight: 600;
  transition:
    border-color 0.15s,
    background 0.15s;
  user-select: none;
}

.afsl-cb-label input[type="checkbox"] {
  display: none; /* ซ่อน checkbox จริง ใช้ style บน label แทน */
}

/* สถานะ "checked" → เปลี่ยนสีพื้นหลัง */
.afsl-cb-label:has(input:checked) {
  border-color: var(--afsl-primary);
  background: #e8f5e9;
  color: var(--afsl-primary);
}
.afsl-cb-all:has(input:checked) {
  border-color: var(--afsl-muted);
  background: #f0f0f0;
  color: var(--afsl-text);
}
.afsl-cb-shopee:has(input:checked) {
  border-color: #ee4d2d;
  background: #fff3f0;
  color: #ee4d2d;
}
.afsl-cb-lazada:has(input:checked) {
  border-color: #0f0f96;
  background: #eff0fb;
  color: #0f0f96;
}

/* ── Section header ─────────────────────────────────────────────────────────── */
.afsl-comparison-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.afsl-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--afsl-text);
  margin: 0;
}

.afsl-count {
  font-size: 13px;
  color: var(--afsl-muted);
  background: var(--afsl-bg);
  border: 1px solid var(--afsl-border);
  border-radius: 20px;
  padding: 3px 12px;
  transition: color 0.2s;
}

/* ── Price comparison table ─────────────────────────────────────────────────── */
.afsl-table-wrap {
  overflow-x: auto;
  border-radius: var(--afsl-radius);
  border: 1px solid var(--afsl-border);
  box-shadow: var(--afsl-shadow);
}

.afsl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--afsl-font-size);
  background: #fff;
}

.afsl-table thead th {
  background: var(--afsl-primary);
  color: #fff;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.afsl-table thead th.col-sold,
.afsl-table thead th.col-rating,
.afsl-table thead th.col-price,
.afsl-table thead th.col-action,
.afsl-table thead th.col-source {
  text-align: center;
}

.afsl-table tbody tr {
  border-bottom: 1px solid var(--afsl-border);
}
.afsl-table tbody tr:last-child {
  border-bottom: none;
}
.afsl-table tbody tr:hover {
  background: var(--afsl-row-hover-bg);
}

.afsl-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

.afsl-table td.col-sold,
.afsl-table td.col-rating,
.afsl-table td.col-price,
.afsl-table td.col-action,
.afsl-table td.col-source {
  text-align: center;
}

/* column widths */
.afsl-table .col-img {
  width: 72px;
}
.afsl-table .col-price {
  width: 80px;
}
.afsl-table .col-sold {
  width: 90px;
}
.afsl-table .col-rating {
  width: 110px;
}
.afsl-table .col-action {
  width: 140px;
}
.afsl-table .col-source {
  width: 100px;
}

.afsl-thumb {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--afsl-border);
  display: block;
  background: #fff;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.afsl-no-img {
  font-size: 28px;
  display: block;
  text-align: center;
}

.afsl-product-name {
  color: var(--afsl-text);
  font-weight: 500;
  text-decoration: none;
  line-height: 1.4;
}
.afsl-product-name:hover {
  color: var(--afsl-primary);
}

.afsl-price {
  font-weight: 700;
  font-size: 15px;
  color: #d32f2f;
  letter-spacing: 0.3px;
}
.afsl-price-na {
  color: #ccc;
}

.afsl-sold {
  color: var(--afsl-muted);
  font-size: 13px;
  font-weight: 600;
}

.afsl-rating-num {
  font-size: 13px;
  color: var(--afsl-muted);
  margin-left: 4px;
}

/* sortable header */
.afsl-sortable {
  cursor: pointer;
  user-select: none;
}
.afsl-sortable:hover {
  background: var(--afsl-primary-dark);
}
.afsl-sort-icon {
  font-size: 11px;
  opacity: 0.8;
}

/* ── Buy button ─────────────────────────────────────────────────────────────── */
.afsl-btn-buy {
  display: inline-block;
  background: var(--afsl-btn-bg);
  color: #fff !important; /* !important ป้องกัน theme override ค่า a { color } */
  padding: 7px 12px;
  border-radius: var(--afsl-btn-radius);
  font-size: var(--afsl-btn-font-size);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s;
}
.afsl-btn-buy:hover {
  background: var(--afsl-btn-hover-bg);
  color: #fff !important;
}

/* ── Source badge ───────────────────────────────────────────────────────────── */
.afsl-source-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.afsl-source-shopee {
  background: #ee4d2d !important;
  color: #ffffff !important;
}
.afsl-source-lazada {
  background: #0f0f96 !important;
  color: #ffffff !important;
}

/* ── Stars ──────────────────────────────────────────────────────────────────── */
.afsl-star {
  font-size: 14px;
}
.afsl-star.full {
  color: var(--afsl-gold);
}
.afsl-star.half {
  color: var(--afsl-gold);
  opacity: 0.6;
}
.afsl-star.empty {
  color: #ddd;
}

/* ── Best of list ───────────────────────────────────────────────────────────── */
.afsl-bestof-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.afsl-bestof-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--afsl-border);
  border-radius: var(--afsl-radius);
  padding: 14px 16px;
  box-shadow: var(--afsl-shadow);
  transition:
    transform 0.15s,
    box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}
.afsl-bestof-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Top 3 highlight */
.afsl-bestof-card.rank-top-1 {
  border-left: 4px solid var(--afsl-gold);
}
.afsl-bestof-card.rank-top-2 {
  border-left: 4px solid var(--afsl-silver);
}
.afsl-bestof-card.rank-top-3 {
  border-left: 4px solid var(--afsl-bronze);
}

/* [4] 🔥 ขายดีสุด badge — อันดับ 1 */
.afsl-hot-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px 3px 14px;
  border-bottom-left-radius: 8px;
  letter-spacing: 0.3px;
  z-index: 1;
}

.afsl-rank-badge {
  font-size: 24px;
  min-width: 40px;
  text-align: center;
  flex-shrink: 0;
}
.rank-normal .afsl-rank-badge {
  font-size: 16px;
  font-weight: 700;
  color: var(--afsl-muted);
}

.afsl-card-img {
  flex-shrink: 0;
}
.afsl-card-img img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--afsl-border);
  display: block;
  background: #fff;
}

.afsl-card-info {
  flex: 1;
  min-width: 0;
}

.afsl-card-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
.afsl-card-title a {
  color: var(--afsl-text);
  text-decoration: none;
}
.afsl-card-title a:hover {
  color: var(--afsl-primary);
}

.afsl-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.afsl-stars-sm .afsl-star {
  font-size: 13px;
}

.afsl-sold-badge {
  font-size: 12px;
  background: #e8f5e9;
  color: var(--afsl-primary);
  border-radius: 12px;
  padding: 2px 10px;
  font-weight: 600;
}

.afsl-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  min-width: 130px;
}

/* [3] ราคาใหญ่ โดดเด่น */
.afsl-bestof-price {
  font-size: 20px;
  font-weight: 800;
  color: #d32f2f;
  letter-spacing: -0.3px;
  line-height: 1;
}

/* [1] CTA button */
.afsl-btn-cta {
  white-space: nowrap;
  font-size: 13px !important;
  padding: 8px 14px !important;
  letter-spacing: 0.2px;
}

/* ── Disclaimer ─────────────────────────────────────────────────────────────── */
.afsl-empty,
.afsl-disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--afsl-muted);
  margin-top: 12px;
  padding: 8px 0;
}

/* ── กันถูก fixed footer ของ theme ทับ ──────────────────────────────────────── */
.afsl-comparison-wrap,
.afsl-bestof-wrap {
  padding-bottom: 80px;
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .afsl-filter-form {
    flex-direction: column;
  }
  .afsl-filter-group {
    min-width: 100%;
  }
  .afsl-source-filter {
    gap: 8px;
  }
  .afsl-cb-label {
    font-size: 12px;
    padding: 4px 10px;
  }

  /* ── Table → Card layout ── */
  .afsl-table-wrap {
    border: none;
    box-shadow: none;
    background: transparent;
  }

  .afsl-table,
  .afsl-table tbody,
  .afsl-table tr {
    display: block;
    width: 100%;
  }

  /* ซ่อน thead */
  .afsl-table thead {
    display: none;
  }

  /* แต่ละ row = card */
  .afsl-table tbody tr.afsl-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--afsl-border);
    border-radius: var(--afsl-radius);
    box-shadow: var(--afsl-shadow);
    padding: 12px;
    margin-bottom: 10px;
  }
  .afsl-table tbody tr.afsl-row:hover {
    background: var(--afsl-row-hover-bg);
  }

  /* รูป — ซ้ายบน */
  .afsl-table td.col-img {
    width: 64px;
    flex-shrink: 0;
    padding: 0;
    text-align: left;
  }
  .afsl-thumb {
    width: 64px;
    height: 64px;
  }

  /* ชื่อ — ขวาของรูป เต็มความกว้างที่เหลือ */
  .afsl-table td.col-name {
    flex: 1;
    min-width: 0;
    padding: 0;
    font-size: 13px;
    line-height: 1.4;
    text-align: left;
  }

  /* ราคา / ขายแล้ว / Rating / แหล่ง — แถวล่าง เรียงซ้าย→ขวา */
  .afsl-table td.col-price,
  .afsl-table td.col-sold,
  .afsl-table td.col-rating,
  .afsl-table td.col-source {
    padding: 0;
    text-align: left;
    font-size: 12px;
  }

  .afsl-table td.col-price {
    width: auto;
  }
  .afsl-table td.col-sold {
    width: auto;
  }
  .afsl-table td.col-rating {
    width: auto;
  }
  .afsl-table td.col-source {
    width: auto;
    margin-left: auto;
  }

  /* ปุ่ม — เต็มความกว้าง ล่างสุด */
  .afsl-table td.col-action {
    width: 100%;
    padding: 4px 0 0;
    text-align: center;
  }
  .afsl-btn-buy {
    width: 100%;
    display: block;
    padding: 10px;
    font-size: 14px;
    text-align: center;
  }

  /* label กำกับแต่ละ cell */
  .afsl-table td.col-price::before {
    content: "ราคา: ";
    font-size: 11px;
    color: var(--afsl-muted);
  }
  .afsl-table td.col-sold::before {
    content: "ขายแล้ว: ";
    font-size: 11px;
    color: var(--afsl-muted);
  }

  /* ── Best of card — mobile layout ── */
  .afsl-bestof-card {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }

  /* rank badge เล็กลง */
  .afsl-rank-badge {
    font-size: 20px;
    min-width: 28px;
  }
  .rank-normal .afsl-rank-badge {
    font-size: 14px;
  }

  /* รูป เล็กลง */
  .afsl-card-img img {
    width: 64px;
    height: 64px;
  }

  /* ชื่อ — flex ขยายเต็มที่เหลือ */
  .afsl-card-info {
    flex: 1;
    min-width: 0;
  }
  .afsl-card-title {
    font-size: 13px;
    margin-bottom: 4px;
  }

  /* meta — sold + source เรียงซ้าย→ขวา */
  .afsl-card-meta {
    gap: 5px;
  }
  .afsl-sold-badge {
    font-size: 11px;
    padding: 2px 8px;
  }

  /* ราคา + ปุ่ม — เต็มความกว้าง อยู่แถวล่างสุด */
  .afsl-card-right {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    min-width: 0;
    gap: 10px;
  }

  .afsl-bestof-price {
    font-size: 18px;
    flex-shrink: 0;
  }

  /* ปุ่ม CTA — ขยายเต็มที่เหลือ */
  .afsl-btn-cta {
    flex: 1;
    text-align: center;
    font-size: 13px !important;
    padding: 10px 8px !important;
  }
}
/* ==========================================================================
   Mobile Vertical Card Layout (UX Optimized)
   ========================================================================== */
@media screen and (max-width: 768px) {
  /* 1. Reset พื้นฐานตารางให้กลายเป็น Card */
  .afsl-table thead {
    display: none !important;
  }

  .afsl-table,
  .afsl-table tbody,
  .afsl-table tr,
  .afsl-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  /* 2. ดีไซน์ Card: ใช้เงาแทนเส้นขอบ เพื่อความโปร่งสบายตา */
  .afsl-table tr.afsl-row {
    display: flex !important;
    flex-wrap: wrap;
    background: #ffffff;
    border: none;
    border-radius: 12px; /* โค้งมนมากขึ้นดูทันสมัย */
    margin-bottom: 20px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* เงาบางๆ เพิ่มมิติ */
  }

  .afsl-table td {
    padding: 0 !important;
    background: transparent !important;
  }

  /* ปรับปรุงรูปภาพให้แสดงผลสวยงามขึ้น */
  .afsl-table .col-img {
    order: 1;
    width: 100% !important;
    text-align: center;
    margin-bottom: 12px;
    padding: 0 10px !important; /* เพิ่ม Padding เล็กน้อยกันรูปชิดขอบเกินไป */
  }

  .afsl-table .col-img img {
    width: 100%; /* ให้รูปกางเต็มความกว้างการ์ด */
    max-width: 200px; /* จำกัดไม่ให้ใหญ่จนแตกในจอใหญ่เกินไป */
    height: 180px; /* กำหนดความสูงให้คงที่ */
    object-fit: contain; /* เปลี่ยนจาก cover เป็น contain เพื่อให้เห็นภาพครบทุกส่วนไม่โดนตัด */
    background-color: #f9f9f9; /* ใส่สีพื้นหลังอ่อนๆ เพื่อให้รูปดูมีกรอบ */
    border-radius: 8px;
    margin: 0 auto;
    border: 1px solid #f0f0f0; /* ใส่เส้นขอบบางๆ เพื่อแยกรูปออกจากพื้นหลังสีขาว */
  }

  /* 4. ชื่อสินค้า: จัดชิดซ้าย หรือกลาง ตามความเหมาะสม */
  .afsl-table .col-name {
    order: 2;
    width: 100% !important;
    margin-bottom: 8px;
  }
  .afsl-product-name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    color: #222;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* 5. ราคา: เด่นที่สุดใน Card */
  .afsl-table .col-price {
    order: 3;
    width: 100% !important;
    font-size: 20px;
    color: #ee4d2d;
    font-weight: 700;
    margin-bottom: 12px;
  }

  /* 6. ข้อมูลสนับสนุน: รวม Icon + Text เพื่อลดพื้นที่ซ้ำซ้อน */
  .afsl-table .col-sold,
  .afsl-table .col-rating {
    order: 4;
    width: 50% !important;
    font-size: 13px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .afsl-table .col-rating {
    justify-content: flex-end;
  }

  /* 7. ปุ่ม Action: ปรับสีและขนาดให้กดง่าย */
  .afsl-table .col-action {
    order: 5;
    width: 100% !important;
    margin-top: 16px;
  }
  .afsl-btn-buy {
    display: block;
    width: 100%;
    padding: 14px 0;
    background-color: #ee4d2d;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s;
  }
  .afsl-btn-buy:active {
    background-color: #c93b1e;
  }

  /* 8. ซ่อนส่วนที่ไม่จำเป็น (เช่น source ที่ซ้ำซ้อน) */
  .afsl-table .col-source {
    display: none !important;
  }
}
