* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: "Segoe UI", Tahoma, sans-serif; color: #222; }
body { display: flex; flex-direction: column; overflow: hidden; }
.hidden { display: none !important; }
.pin-div { background: transparent; border: none; }

.adbar {
  background: #f2f3f5; color: #888; text-align: center;
  font-size: 13px; padding: 6px; border-bottom: 1px solid #e3e5e8; flex: none;
}

.topbar {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 8px 12px; background: #fff; border-bottom: 1px solid #e3e5e8;
}
.brand { font-size: 18px; white-space: nowrap; }
.search { flex: 1; display: flex; min-width: 100px; }
.search input {
  flex: 1; padding: 8px 10px; border: 1px solid #ccd0d5;
  border-radius: 6px 0 0 6px; font-size: 14px; outline: none; min-width: 0;
}
.search button {
  border: 1px solid #ccd0d5; border-left: none; background: #f5f6f7;
  border-radius: 0 6px 6px 0; padding: 0 12px; cursor: pointer;
}
.near-btn {
  border: none; background: #1877f2; color: #fff; font-weight: 600;
  padding: 9px 14px; border-radius: 6px; cursor: pointer; white-space: nowrap; font-size: 14px;
}
.near-btn:active { transform: scale(.97); }
.seller-link {
  display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap;
  border: 1px solid #ccd0d5; background: #fff; color: #333; font-weight: 600;
  padding: 8px 12px; border-radius: 6px; font-size: 14px;
}
.icon-btn {
  border: 1px solid #ccd0d5; background: #fff; color: #333; cursor: pointer;
  padding: 8px 11px; border-radius: 6px; font-size: 17px; line-height: 1;
}
.icon-btn:active { transform: scale(.92); }

.chips-row {
  display: flex; align-items: center; flex: none;
  background: #fff; border-bottom: 1px solid #e3e5e8;
}
.chips {
  display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; flex: 1;
  white-space: nowrap; -webkit-overflow-scrolling: touch;
}
.reorder-btn {
  flex: none; border: none; background: none; cursor: pointer; font-size: 18px;
  padding: 8px 12px; color: #666; border-left: 1px solid #eee;
}
.reorder-btn:active { transform: scale(.92); }

/* modal จัดลำดับหมวด */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 12px; width: 380px; max-width: 100%;
  max-height: 80vh; display: flex; flex-direction: column; padding: 16px;
}
.modal-card h3 { margin: 0 0 4px; font-size: 18px; }
.modal-hint { color: #777; font-size: 13px; margin: 0 0 10px; }
.reorder-list { overflow-y: auto; flex: 1; }
.reorder-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 8px;
  border: 1px solid #e3e5e8; border-radius: 8px; margin-bottom: 6px; background: #fff;
}
.reorder-item.dragging { opacity: .45; }
.reorder-item .rh { cursor: grab; color: #b0b6bf; font-size: 18px; }
.reorder-item .rname { flex: 1; font-size: 15px; }
.reorder-item .rord {
  border: 1px solid #ccd0d5; background: #f5f6f7; border-radius: 6px;
  cursor: pointer; padding: 4px 9px; font-size: 12px;
}
.modal-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.rbtn { border: none; background: #1877f2; color: #fff; font-weight: 600; padding: 9px 16px; border-radius: 8px; cursor: pointer; }
.rbtn.ghost { background: #eceef1; color: #333; }
.chip {
  border: 1px solid #ccd0d5; background: #fff; border-radius: 20px;
  padding: 6px 14px; font-size: 14px; cursor: pointer; user-select: none; white-space: nowrap;
}
.chip.active { background: #1877f2; color: #fff; border-color: #1877f2; }

.body { flex: 1; position: relative; display: flex; min-height: 0; }
#map { flex: 1; height: 100%; z-index: 1; }

/* ---------- Panel (รายการร้าน / รายละเอียด) ---------- */
.panel {
  width: 360px; max-width: 42vw; background: #fff; border-left: 1px solid #e3e5e8;
  display: flex; flex-direction: column; min-height: 0;
}
.panel-handle { display: none; }              /* โชว์เฉพาะมือถือ */
.map-toggle { display: none; }                 /* โชว์เฉพาะมือถือ */
.panel-top {
  flex: none; display: flex; flex-direction: column; gap: 8px;
  padding: 8px 14px; border-bottom: 1px solid #eee;
}
.list-search {
  width: 100%; padding: 8px 10px; border: 1px solid #ccd0d5; border-radius: 7px;
  font-size: 14px; outline: none;
}
.list-search:focus { border-color: #1877f2; }
.panel-top-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 13px; flex-wrap: wrap;
}
.showall-ctl { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer; font-weight: 600; }
.showall-ctl input { width: 16px; height: 16px; }
#radius:disabled { opacity: .4; }
.radius-ctl { white-space: nowrap; }
.radius-ctl input[type=range] { vertical-align: middle; width: 110px; }
.status { color: #666; }
.panel-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.view-tabs { display: flex; flex: none; border-bottom: 1px solid #e3e5e8; }
.vtab {
  flex: 1; border: none; background: #fff; cursor: pointer; padding: 11px 8px;
  font-size: 14px; font-weight: 600; color: #666; border-bottom: 3px solid transparent;
}
.vtab.active { color: #1877f2; border-bottom-color: #1877f2; }

.prod-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer;
}
.prod-item:hover { background: #f7f8fa; }
.prod-item .pi-name { font-weight: 600; font-size: 15px; }
.prod-item .pi-sub { color: #666; font-size: 13px; margin-top: 2px; }
.prod-item .pprice { color: #e5533d; font-weight: 700; white-space: nowrap; }

/* list */
.list-body { padding: 4px 0; }
.shop-item {
  padding: 11px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer;
}
.shop-item:hover { background: #f7f8fa; }
.shop-item .sname { font-weight: 600; font-size: 15px; }
.shop-item .smeta { color: #666; font-size: 13px; margin-top: 2px; }
.shop-item .sdist { color: #1877f2; font-weight: 600; }
.shop-item .scount {
  display: inline-block; background: #eef3ff; color: #1877f2; border-radius: 10px;
  padding: 1px 8px; font-size: 12px; margin-top: 4px;
}
.ai-badge {
  display: inline-block; background: #eef0f3; color: #6b7686; border-radius: 8px;
  padding: 0 7px; font-size: 11px; font-weight: 600; vertical-align: middle;
}
.ai-note {
  background: #f2f4f7; color: #5b6b7d; border-radius: 8px; padding: 8px 10px;
  font-size: 13px; margin: 6px 0;
}
.claim-link { display: inline-block; margin-top: 6px; color: #1877f2; font-weight: 600; text-decoration: none; }
.claim-link:hover { text-decoration: underline; }
.empty { padding: 20px 14px; color: #888; text-align: center; }

/* detail */
.back-btn {
  border: none; background: #f0f1f3; padding: 8px 12px; width: 100%; text-align: left;
  cursor: pointer; font-size: 14px; border-bottom: 1px solid #e3e5e8;
}
#detailBody { padding: 14px; }
#detailBody h2 { margin: 0 0 4px; font-size: 19px; }
#detailBody .addr { color: #666; font-size: 13px; margin-bottom: 3px; }
#detailBody .dist { color: #1877f2; font-size: 13px; font-weight: 600; }
#detailBody .desc { font-size: 14px; margin: 8px 0; }
.prod {
  display: flex; justify-content: space-between; gap: 8px;
  border-top: 1px solid #eee; padding: 8px 0; font-size: 14px;
}
.prod .pname { font-weight: 500; }
.prod .pcat { color: #888; font-size: 12px; }
.prod .pprice { color: #e5533d; font-weight: 700; white-space: nowrap; }

/* ---------- มือถือ: panel เป็น bottom sheet ---------- */
@media (max-width: 720px) {
  .brand b { display: none; }
  .near-btn .lbl { display: none; }
  .search input { font-size: 16px; }         /* กัน iOS zoom */

  /* มือถือ: รายการอยู่บน 60% · แผนที่อยู่ล่าง 40% */
  .body { flex-direction: column; }
  .panel {
    order: -1; position: static; width: auto; max-width: none;
    height: 60%; flex: 0 0 60%;
    border-left: none; border-bottom: 1px solid #e3e5e8;
  }
  #map { height: 40%; flex: 0 0 40%; }
  .panel-handle { display: none; }

  /* ปุ่มซ่อน/แสดงแผนที่ (เฉพาะมือถือ) */
  .map-toggle {
    display: inline-flex; align-items: center; gap: 5px;
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: 12px; z-index: 1200;
    padding: 7px 15px; border: none; border-radius: 20px;
    background: #1f6feb; color: #fff; font-size: 13px; font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,.3); cursor: pointer;
  }
  .body.map-hidden #map { display: none; }
  .body.map-hidden .panel { height: 100%; flex: 1 1 100%; border-bottom: none; }
}

/* ---------- ปุ่มบัญชีผู้ซื้อ + โมดัล ---------- */
.acct-btn {
  display: inline-flex; align-items: center; white-space: nowrap;
  border: 1px solid #ccd0d5; background: #fff; color: #333; font-weight: 600;
  padding: 8px 12px; border-radius: 6px; font-size: 14px; cursor: pointer;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}
.acct-btn:active { transform: scale(.97); }
.acct-btn .lbl { overflow: hidden; text-overflow: ellipsis; }
.auth-card { position: relative; width: 340px; }
.auth-x { position: absolute; top: 10px; right: 12px; border: none; background: transparent; font-size: 18px; color: #888; cursor: pointer; line-height: 1; }
.auth-tabs { display: flex; gap: 6px; margin: 8px 0 12px; }
.atab { flex: 1; border: 1px solid #ccd0d5; background: #f2f3f5; color: #444; font-weight: 600; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.atab.active { background: #1877f2; color: #fff; border-color: #1877f2; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-in { padding: 10px 12px; border: 1px solid #ccd0d5; border-radius: 8px; font-size: 15px; outline: none; }
.auth-in:focus { border-color: #1877f2; }
.auth-submit { border: none; background: #1877f2; color: #fff; font-weight: 700; padding: 11px; border-radius: 8px; cursor: pointer; font-size: 15px; margin-top: 2px; }
.auth-submit.ghost { background: #eceef1; color: #333; }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-err { background: #fdecea; color: #b3261e; border: 1px solid #f5c2be; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 10px; }
.auth-me { font-size: 16px; margin: 10px 0 16px; }
.auth-foot { color: #888; font-size: 12px; margin: 12px 0 0; line-height: 1.5; }
.auth-google { margin-top: 12px; }
.auth-or { display: flex; align-items: center; text-align: center; color: #999; font-size: 12px; margin: 6px 0 10px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; border-top: 1px solid #e3e5e8; }
.auth-or span { padding: 0 10px; }
#gsiButton { display: flex; justify-content: center; }
@media (max-width: 720px) { .acct-btn .lbl { display: none; } }
