/* โทนสี: เขียวแผงวงจร (PCB) + เหลืองป้ายราคา */
:root {
  --board: #0f4c3a;
  --board-2: #176b52;
  --ink: #16201c;
  --muted: #5d6b65;
  --line: #d3ddd8;
  --paper: #f3f6f4;
  --white: #ffffff;
  --tag: #f5c518;
  --tag-ink: #3a2e00;
  --danger: #b3261e;
  --ok: #1e7a45;
  --radius: 6px;
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; }
img { max-width: 100%; display: block; }
a { color: var(--board-2); }
:focus-visible { outline: 3px solid var(--tag); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; font-weight: 600; }
h1 { font-size: 1.75rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 24px; padding-bottom: 48px; min-height: 60vh; }
.muted { color: var(--muted); }

/* header */
.site-header { background: var(--board); color: var(--white); }
.header-row { display: flex; align-items: center; gap: 16px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.logo { color: var(--white); font-weight: 600; font-size: 1.25rem; text-decoration: none; letter-spacing: -.01em; }
.header-search { flex: 1 1 320px; display: flex; }
.header-search input { flex: 1; border: 0; border-radius: var(--radius) 0 0 var(--radius); padding: 10px 12px; font: inherit; min-width: 0; }
.header-search button { border: 0; background: var(--tag); color: var(--tag-ink); font: inherit; font-weight: 600; padding: 0 16px; border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer; }
.header-nav { display: flex; align-items: center; gap: 16px; }
.header-nav a { color: var(--white); text-decoration: none; }
.cat-rail { background: var(--board-2); overflow-x: auto; }
.cat-rail .wrap { display: flex; gap: 4px; white-space: nowrap; }
.cat-rail a { color: #e6f2ec; text-decoration: none; padding: 9px 12px; font-size: .95rem; }
.cat-rail a[aria-current] { color: var(--white); box-shadow: inset 0 -3px 0 var(--tag); }
.cat-rail .rail-check { margin-left: auto; color: var(--tag); }

/* buttons & forms */
.btn { display: inline-block; border: 1px solid var(--board); background: var(--board); color: var(--white); padding: 9px 16px; border-radius: var(--radius); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; color: var(--board); }
.btn-post { background: var(--tag); border-color: var(--tag); color: var(--tag-ink); font-weight: 600; }
.btn-line { background: #06c755; border-color: #06c755; width: 100%; text-align: center; }
.btn-google { background: var(--white); color: var(--ink); border-color: var(--line); width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--board-2); text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); color: var(--ink); width: 100%; }
label { display: block; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
.stack { display: grid; gap: 14px; max-width: 640px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 500; margin-bottom: 4px; }
.radio { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin-right: 16px; }
.radio input { width: auto; margin: 0; }
.form-msg { min-height: 1.5em; margin: 0; }
.form-msg.error { color: var(--danger); }
.form-msg.success { color: var(--ok); }
.hint { font-size: .9rem; color: var(--muted); margin: -6px 0 0; }
.notice { background: #fff8d6; border: 1px solid #ecd77a; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.notice-under_review, .notice-rejected { background: #fdecea; border-color: #f0b8b2; }

/* home */
.intro { padding: 12px 0 20px; max-width: 46rem; }
.intro h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -.02em; }
.intro p { color: var(--muted); margin: 0; }
.page-title { margin-bottom: 16px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 16px 0 8px; }
.result-count { color: var(--muted); font-size: .9rem; margin: 8px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.grid-ad { grid-column: 1 / -1; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; display: flex; flex-direction: column; overflow: hidden; }
.card:hover { border-color: var(--board-2); }
.card-img { position: relative; aspect-ratio: 1; background: #e6ece9; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.card-body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.card-title { font-size: .98rem; font-weight: 500; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { margin: 0; color: var(--muted); font-size: .85rem; }
.type-chip { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 3px; background: var(--board); color: var(--white); }
.card-img .type-chip { position: absolute; top: 8px; left: 8px; }
.card-img .card-badge-new { position: absolute; top: 8px; right: 8px; background: var(--danger); color: var(--white); border-color: var(--danger); margin-left: 0; }
.type-buy { background: #2d4f8a; }
.type-trade { background: #7a4b12; }

/* ป้ายราคาแบบสติกเกอร์ ส่วนที่เด่นที่สุดของหน้า */
.price-tag { justify-self: start; display: inline-block; background: var(--tag); color: var(--tag-ink); font-weight: 600; padding: 2px 10px 2px 14px; border-radius: 2px 4px 4px 2px; position: relative; font-variant-numeric: tabular-nums; }
.price-tag::before { content: ""; position: absolute; left: 5px; top: 50%; width: 4px; height: 4px; margin-top: -2px; border-radius: 50%; background: var(--tag-ink); opacity: .55; }
.price-lg { font-size: 1.6rem; padding: 4px 16px 4px 22px; margin: 4px 0 16px; }
.price-lg::before { left: 8px; width: 6px; height: 6px; margin-top: -3px; }

.pager { display: flex; gap: 16px; justify-content: center; align-items: center; margin-top: 28px; }
.empty { background: var(--white); border: 1px dashed var(--line); padding: 32px; text-align: center; border-radius: var(--radius); }

/* listing detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; }
@media (max-width: 800px) { .detail { grid-template-columns: 1fr; } }
.gallery-main { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
.gallery-thumbs button { border: 1px solid var(--line); padding: 0; background: none; border-radius: 4px; cursor: pointer; flex: 0 0 72px; }
.gallery-thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 3px; }
.gallery-empty { aspect-ratio: 1; display: grid; place-items: center; background: #e6ece9; border-radius: var(--radius); color: var(--muted); }
.detail-info h1 { margin-top: 10px; }
.specs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 20px; }
.specs dt { color: var(--muted); }
.specs dd { margin: 0; }
.seller { border-top: 1px solid var(--line); padding-top: 16px; }
.seller-name { font-weight: 600; font-size: 1.1rem; margin-right: 8px; }
.badge { display: inline-block; font-size: .8rem; padding: 2px 8px; border-radius: 3px; border: 1px solid var(--line); background: var(--white); }
.badge-l2 { border-color: #06c755; color: #04723a; }
.badge-l3, .badge-l4 { background: var(--board); color: var(--white); border-color: var(--board); }
.owner-actions { display: flex; gap: 8px; margin-top: 16px; }
.description { max-width: 46rem; }
.safety-box { background: var(--white); border-left: 4px solid var(--tag); padding: 4px 20px 12px; margin: 24px 0; max-width: 46rem; }
.safety-box h2 { margin-top: 12px; font-size: 1.05rem; }
.safety-box ol { padding-left: 1.2rem; margin: 0; }
.report { margin-top: 24px; max-width: 46rem; }
.report summary { cursor: pointer; color: var(--danger); }
.report form { display: grid; gap: 10px; margin-top: 12px; }

/* auth / post / me */
.auth { max-width: 420px; margin: 0 auto; }
.divider { text-align: center; color: var(--muted); margin: 20px 0; border-top: 1px solid var(--line); line-height: 0; }
.divider span { background: var(--paper); padding: 0 10px; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews img { width: 88px; height: 88px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.my-listings { width: 100%; border-collapse: collapse; background: var(--white); }
.my-listings th, .my-listings td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
.status { font-size: .85rem; }
.status-active { color: var(--ok); }
.status-pending { color: #8a6d00; }
.status-under_review, .status-rejected { color: var(--danger); }
.check { max-width: 640px; }
.check-result { margin: 16px 0; padding: 14px; border-radius: var(--radius); display: none; }
.check-result.found { display: block; background: #fdecea; border: 1px solid #f0b8b2; }
.check-result.clear { display: block; background: #eaf5ee; border: 1px solid #b4dcc2; }
.prose { max-width: 46rem; }
.error-page { text-align: center; padding: 48px 0; }

/* ads */
.ad-slot { margin: 16px 0; min-height: 90px; }
.ad-label { display: block; font-size: .75rem; color: var(--muted); }
.ad-placeholder { display: grid; place-items: center; border: 1px dashed var(--line); color: var(--muted); }

/* footer */
.site-footer { background: var(--ink); color: #c7d3cd; font-size: .9rem; }
.footer-row { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 20px; padding-bottom: 20px; }
.footer-row p { margin: 0; }
.footer-row nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-footer a { color: #e6f2ec; }

@media (max-width: 600px) {
  .header-row { gap: 10px; }
  .header-nav { margin-left: auto; gap: 12px; }
  .header-search { order: 3; flex-basis: 100%; }
  .header-nav .btn-post { padding: 6px 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-body { padding: 8px; }
}

/* ---------- แชท (หน้า /chats แบบหน้าเดียว: รายการทางซ้าย + ห้องสนทนาทางขวา) ---------- */
.chat-app { display: grid; grid-template-columns: 300px 1fr; gap: 0; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 60vh; }
.chat-list-pane { border-right: 1px solid var(--line); padding: 14px; overflow-y: auto; max-height: 78vh; }
.chat-list-pane h1 { font-size: 1.1rem; margin: 0 0 8px; }
.chat-status { font-size: .9rem; }
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.chat-item { width: 100%; display: flex; gap: 10px; align-items: center; padding: 8px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: var(--radius); font: inherit; }
.chat-item:hover, .chat-item.active { background: var(--paper); }
.chat-item.unread .chat-item-body strong { font-weight: 700; }
.chat-item img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; flex: none; }
.chat-item-body { display: grid; gap: 1px; min-width: 0; flex: 1; }
.chat-item-body strong { font-size: .92rem; }
.chat-item-title { font-size: .8rem; color: var(--board-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-last { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: .72rem; color: var(--muted); align-self: flex-start; }
.chat-panel { display: flex; flex-direction: column; padding: 14px; min-height: 0; }
.chat-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.chat-head-info { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; flex: 1; }
.chat-listing-link { font-size: .85rem; color: var(--board-2); }
.chat-head-actions { display: flex; gap: 10px; }
.chat-head-actions .danger { color: var(--danger); }
.chat-warning { background: #fdecea; border: 1px solid #f0b8b2; padding: 10px 12px; border-radius: var(--radius); margin-bottom: 8px; font-size: .9rem; }
.chat-messages { list-style: none; margin: 0; padding: 4px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 300px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; }
.msg-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { display: block; font-size: .72rem; opacity: .7; margin-top: 2px; }
.msg-warn { margin: 4px 0 0; font-size: .78rem; color: var(--danger); }
.msg.mine { align-self: flex-end; background: var(--board); color: var(--white); border-bottom-right-radius: 3px; }
.msg.theirs { align-self: flex-start; background: #e9efec; border-bottom-left-radius: 3px; }
.chat-compose { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; }
.chat-compose textarea { flex: 1; resize: none; }
.chat-blocked { color: var(--danger); text-align: center; margin: 8px 0 0; }
@media (max-width: 800px) {
  .chat-app { grid-template-columns: 1fr; }
  .chat-list-pane { max-height: none; }
  .chat-panel { display: none; }
  .chat-app.is-open .chat-panel { display: flex; }
  .chat-app.is-open .chat-list-pane { display: none; }
}
.chat-back { display: none; }
@media (max-width: 800px) { .chat-back { display: inline-block; margin-bottom: 4px; } }

/* ---------- รีวิวและคะแนน ---------- */
.stars { color: #d9a400; letter-spacing: 1px; }
.stars-off { color: var(--line); }
.trust strong { font-variant-numeric: tabular-nums; }
.reviews { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; max-width: 46rem; }
.reviews li { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.reviews p { margin: 4px 0 0; }
.card-plain { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; display: grid; gap: 8px; max-width: 560px; }
.card-plain p { margin: 0; }
.star-input { display: inline-flex; flex-direction: row-reverse; justify-content: flex-end; gap: 2px; }
.star-input legend { width: 100%; }
.star-input input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.star-input label { font-size: 1.8rem; line-height: 1; color: var(--line); cursor: pointer; font-weight: 400; }
.star-input input:checked ~ label, .star-input label:hover, .star-input label:hover ~ label { color: #d9a400; }
.star-input input:focus-visible + label { outline: 3px solid var(--tag); }
.pick-buyer { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: 420px; width: calc(100% - 32px); }
.pick-buyer h2 { margin-top: 0; }
.pick-buyer form { display: grid; gap: 10px; }
.pick-buyer::backdrop { background: rgba(15, 30, 25, .45); }

/* ---------- แก้ไขประกาศ / KYC / ตาราง ---------- */
.existing .keep { display: grid; gap: 4px; font-weight: 400; font-size: .85rem; justify-items: start; }
.existing .keep input { width: auto; margin: 0; }
.table-scroll { overflow-x: auto; }
.my-listings .actions { white-space: nowrap; display: flex; gap: 12px; }
.kyc { max-width: 640px; }

/* ---------- ดันประกาศ ---------- */
.boost { max-width: 560px; }
.boost-listing { display: flex; gap: 10px; align-items: center; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin: 12px 0; }
.boost-listing img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; }
.boost-pay { background: #fff8d6; border: 1px solid #ecd77a; border-radius: var(--radius); padding: 12px 14px; }
.boost-pay p { margin: 0 0 6px; }
.boost-pay p:last-child { margin-bottom: 0; }

/* ---------- แอดมิน ---------- */
.admin-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 16px; }
.admin-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: inherit; display: grid; gap: 4px; }
.admin-card:hover { border-color: var(--board-2); }
.admin-card strong { font-size: 1.8rem; color: var(--board); font-variant-numeric: tabular-nums; }
.admin-card span { color: var(--muted); font-size: .9rem; }
.admin-tabs { display: flex; gap: 4px; margin: 12px 0 16px; flex-wrap: wrap; }
.admin-tabs a { text-decoration: none; padding: 8px 14px; border-radius: var(--radius); background: var(--white); border: 1px solid var(--line); color: inherit; font-size: .9rem; }
.admin-tabs a[aria-current] { background: var(--board); color: var(--white); border-color: var(--board); }
.admin-row { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.admin-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; flex: none; }
.admin-row-body { flex: 1; min-width: 220px; }
.admin-row-body p { margin: 4px 0 0; }
.admin-row-wide .admin-row-body { min-width: 280px; }
.admin-row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-self: center; }
.admin-row-actions-group { display: flex; flex-direction: column; gap: 6px; align-self: center; }
.admin-row-actions-note { flex-direction: column; align-items: stretch; min-width: 220px; }
.admin-row-actions-note textarea { font-size: .85rem; }
.flag-list { color: var(--danger); font-size: .85rem; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--white); }
.badge-new { border-color: var(--danger); color: var(--danger); font-weight: 600; margin-left: 6px; }
.doc-links { display: flex; gap: 12px; flex-wrap: wrap; font-size: .9rem; }

/* ---------- ตารางจัดการหมวดหมู่/ยี่ห้อ/รุ่น/สภาพสินค้า ---------- */
.catalog-table { width: 100%; border-collapse: collapse; background: var(--white); margin-bottom: 8px; }
.catalog-table th, .catalog-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.catalog-table input, .catalog-table select { padding: 6px 8px; font-size: .9rem; }
.catalog-table input[name="name_th"] { min-width: 160px; }
.catalog-table .order-input { width: 64px; }
.catalog-table .row { display: flex; gap: 6px; flex-wrap: nowrap; white-space: nowrap; }
.catalog-new { background: #f7faf8; }
.catalog-new input, .catalog-new select { background: var(--white); }
.admin h2:first-of-type { margin-top: 8px; }
