/* Quote Pro — หน้าต่างขอใบเสนอราคา
 * เป้าหมาย: ไม่ล้นจอทุกอุปกรณ์ (มือถือจอแคบ/แนวนอน/คีย์บอร์ดเด้ง/แท็บเล็ต/เดสก์ท็อป)
 *  - ตั้ง box-sizing ให้ทุกองค์ประกอบในหน้าต่าง (ธีมที่ไม่ตั้ง border-box จะทำให้ช่องกรอก width:100% + padding ล้นขอบ)
 *  - ตัวหน้าต่างเป็นพื้นที่เลื่อนได้ + margin:auto กึ่งกลางอย่างปลอดภัย (เนื้อหาสูงกว่าจอ = เลื่อน ไม่ถูกตัดด้านบน)
 *  - ใช้ dvh/ตัวแปร --q-vh (จาก visualViewport) เพื่อให้สูงตรงกับจอจริงเมื่อแถบเบราว์เซอร์/คีย์บอร์ดเปลี่ยน
 *  - Turnstile ถูกจำกัดในกล่องของมันเอง (JS เลือกขนาด normal/compact ตามความกว้างที่เหลือ)
 */
html.q-lock, html.q-lock body { overflow: hidden !important; }

.q-modal-wrap, .q-modal-wrap *, .q-modal-wrap *::before, .q-modal-wrap *::after { box-sizing: border-box; }

.q-modal-wrap {
    display: none;
    position: fixed; z-index: 999999; left: 0; top: 0; right: 0; bottom: 0;
    width: 100%; height: 100%; height: 100dvh;
    background: rgba(0, 0, 0, .8);
    overflow-x: hidden; overflow-y: auto;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.q-modal-wrap.q-open { display: flex; }

.modal-inner {
    position: relative; margin: auto; width: 100%; max-width: 500px; min-width: 0;
    background: #fff; color: #222; border-radius: 12px; padding: 30px;
    font-size: 15px; line-height: 1.5;
    overflow-wrap: anywhere; word-break: break-word;
}
.modal-inner img, .modal-inner canvas, .modal-inner iframe, .modal-inner video, .modal-inner table { max-width: 100%; }
.modal-content-area { margin-bottom: 20px; line-height: 1.6; }
.modal-content-area:last-child { margin-bottom: 0; }

.close-btn {
    position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; line-height: 44px;
    text-align: center; cursor: pointer; font-size: 26px; color: #333; z-index: 2; user-select: none;
}

.q-input {
    display: block; width: 100%; max-width: 100%; margin: 0 0 12px; padding: 12px;
    border: 1px solid #ddd; border-radius: 6px; background: #fff; color: #222;
    font-size: 16px; /* 16px ขึ้นไป: iOS ไม่ซูมหน้าเองตอนโฟกัสช่องกรอก */
    line-height: 1.4; min-height: 46px;
}
textarea.q-input { resize: vertical; min-height: 70px; }
.q-input:focus { outline: 2px solid #0a3c8c33; border-color: #0a3c8c; }

.q-submit-btn:disabled, #quote-submit-btn:disabled { opacity: .6; cursor: not-allowed; }
#quote-submit-btn, #q-pay-back, .close-btn-action { max-width: 100%; }

#q-error { display: none; background: #fdecea; color: #b71c1c; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }

/* ---------- ช่องที่อยู่ + ปุ่มเลือก ตำบล/อำเภอ/จังหวัด ---------- */
.q-addr-label { display: block; font-size: 13px; color: #555; margin: 0 0 4px; }
.q-area-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; margin: 0 0 8px; padding: 10px 12px; min-height: 46px;
    border: 1px solid #ddd; border-radius: 6px; background: #fff; color: #222;
    font-size: 16px; line-height: 1.4; cursor: pointer; text-align: left; user-select: none; -webkit-tap-highlight-color: transparent;
}
.q-area-btn:focus { outline: 2px solid #0a3c8c33; border-color: #0a3c8c; }
.q-area-btn.q-invalid { border-color: #c62828; background: #fff8f8; }
.q-area-btn .q-area-text { flex: 1 1 auto; min-width: 0; }
.q-area-btn .q-area-text.q-ph { color: #888; }
.q-area-btn .q-area-go { flex: 0 0 auto; color: #0a3c8c; font-size: 13px; white-space: nowrap; }

/* ---------- ข้อความค่าจัดส่ง (ajax) ---------- */
.q-ship { font-size: 13px; line-height: 1.55; color: #444; margin: 0 0 12px; min-height: 0; }
.q-ship:empty { display: none; }
.q-ship .q-ship-line { display: block; }
.q-ship .q-ship-price { font-weight: 700; color: #111; white-space: nowrap; }
.q-ship .q-ship-warn { color: #8a5a00; }
.q-ship .q-ship-err { color: #b71c1c; }
.q-ship .q-link { color: #0a3c8c; text-decoration: underline; cursor: pointer; white-space: nowrap; }
.q-ship .q-ship-opt { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; cursor: pointer; }
.q-ship .q-ship-opt input { flex: 0 0 auto; width: 18px; height: 18px; margin: 2px 0 0; }
.q-ship .q-ship-opt span { flex: 1 1 auto; min-width: 0; }
.q-ship .q-ship-title { font-weight: 600; margin: 4px 0 0; }
.q-ship .q-spin { display: inline-block; width: 11px; height: 11px; margin-right: 6px; vertical-align: -1px; border: 2px solid #bbb; border-top-color: #0a3c8c; border-radius: 50%; animation: q-spin .8s linear infinite; }
.q-ship .q-skip { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; cursor: pointer; }
.q-ship .q-skip input { flex: 0 0 auto; width: 18px; height: 18px; margin: 2px 0 0; }
@keyframes q-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .q-ship .q-spin { animation: none; } }

/* ---------- Turnstile: อยู่ในกล่องของตัวเอง ไม่ดันหน้าต่างกว้างเกินจอ ---------- */
#q-turnstile { display: flex; justify-content: center; max-width: 100%; min-height: 65px; margin: 8px 0; overflow: hidden; }
#q-turnstile.q-ts-compact { min-height: 140px; }
#q-turnstile iframe { max-width: 100%; }
#q-ts-msg { display: none; color: #c62828; font-size: 13px; margin-bottom: 6px; }

/* ---------- หน้าเลือกพื้นที่ (อยู่ในหน้าต่างเดียวกัน ไม่ซ้อนหน้าต่างใหม่) ---------- */
#q-pick { display: none; }
#q-pick.q-show { display: block; }
.q-pick-head { display: flex; align-items: center; gap: 4px; margin: -10px 36px 6px -10px; min-height: 44px; }
.q-pick-back { flex: 0 0 auto; width: 44px; height: 44px; line-height: 42px; text-align: center; font-size: 30px; cursor: pointer; color: #0a3c8c; user-select: none; }
.q-pick-title { flex: 1 1 auto; min-width: 0; font-size: 17px; font-weight: 700; }
.q-crumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.q-crumb { max-width: 100%; padding: 4px 10px; border-radius: 999px; background: #eef2fb; color: #0a3c8c; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; }
.q-crumb.q-cur { background: #0a3c8c; color: #fff; cursor: default; }
.q-pick-search { margin-bottom: 8px !important; }
.q-pick-list {
    list-style: none; margin: 0; padding: 0;
    border: 1px solid #e3e3e3; border-radius: 8px; background: #fff;
    max-height: 50vh;
    max-height: clamp(180px, calc(var(--q-vh, 100vh) - 300px), 420px);
    overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.q-pick-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: 0; padding: 10px 12px; min-height: 46px; border-bottom: 1px solid #f0f0f0;
    cursor: pointer; font-size: 16px; line-height: 1.35; user-select: none; -webkit-tap-highlight-color: transparent;
}
.q-pick-list li:last-child { border-bottom: 0; }
.q-pick-list li:hover, .q-pick-list li:focus { background: #f3f6ff; outline: none; }
.q-pick-list li.q-sel { background: #e8f0fe; font-weight: 600; }
.q-pick-list .q-li-main { flex: 1 1 auto; min-width: 0; }
.q-pick-list .q-li-sub { display: block; font-size: 12.5px; color: #666; font-weight: 400; margin-top: 1px; }
.q-pick-list .q-li-end { flex: 0 0 auto; color: #888; font-size: 13px; white-space: nowrap; }
.q-pick-list .q-li-empty { cursor: default; color: #777; justify-content: center; text-align: center; }
.q-pick-status { font-size: 13px; color: #555; margin-top: 8px; min-height: 18px; }
.q-pick-status .q-link { color: #0a3c8c; text-decoration: underline; cursor: pointer; }
.q-pick-status .q-err { color: #b71c1c; }

/* ---------- หน้าชำระเงิน ---------- */
#q-pay-panel { display: none; text-align: center; }
#q-pay-panel img, #q-pay-panel canvas { max-width: 280px; width: 100%; height: auto; border: 1px solid #eee; border-radius: 8px; }
#q-pay-amount { font-size: 1.6em; font-weight: bold; margin: 8px 0; }
#q-pay-timer { color: #666; margin: 6px 0 12px; }
#q-pay-msg { margin: 10px 0; color: #555; }
#q-pay-net { display: none; margin: 8px 0; padding: 8px 10px; border-radius: 6px; background: #fff7e0; color: #7a5200; font-size: 13px; }

/* ---------- จอแคบ ---------- */
@media (max-width: 480px) {
    .q-modal-wrap { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
    .modal-inner { padding: 22px 14px 16px; border-radius: 10px; }
    .q-pick-head { margin: -14px 34px 4px -8px; }
    .q-pick-list li { padding: 10px; }
}
@media (max-width: 340px) {
    .modal-inner { padding: 20px 10px 12px; font-size: 14px; }
    .q-pick-title { font-size: 15px; }
}
/* จอแนวนอนเตี้ย ๆ */
@media (max-height: 460px) {
    .modal-inner { padding-top: 20px; }
    .q-pick-list { max-height: clamp(140px, calc(var(--q-vh, 100vh) - 210px), 420px); }
}
