/* =====================================================================
   หน้าตาบนมือถือและแท็บเล็ตของหน้าร้าน (โหลดจาก includes/navbar.php และ login.php)
   จอใหญ่กว่า 1023px ไม่เปลี่ยน ยกเว้นกติกาโลโก้ด้านล่าง
   ===================================================================== */
img.site-logo { width: var(--logo-w, auto); height: var(--logo-h, 40px); max-width: none; max-height: none; object-fit: contain; }
.m-only, .tabbar, .m-sheet { display: none; }

@media (max-width: 1023px) {
    body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
    a, button, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

    /* หัวเว็บ */
    header.site-header { top: 0; padding: 8px 12px; margin-bottom: 0; }
    header.site-header > div { padding: 6px 8px 6px 14px; border-radius: 18px; background: rgba(15, 17, 24, .88); gap: 8px; }
    header.site-header img.site-logo { max-width: 120px; max-height: 44px; }
    .m-balance { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 14px; background: rgba(234, 88, 12, .2); color: #ffb183; font-size: 15px; font-weight: 600; white-space: nowrap; }
    .m-balance b { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #ea580c; color: #fff; font: 700 17px/1 Arial, sans-serif; }
    header.site-header button, header.site-header a[href="login.php"] { min-height: 44px; }
    #userDropdownMenu { width: 230px; border-radius: 16px; background: #14161f; }
    #userDropdownMenu a { min-height: 46px; font-size: 15px; }

    /* แถบเมนูล่าง */
    .tabbar { position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: #11131b; border-top: 1px solid #2a2e3d; }
    .tabbar > * { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 54px; padding: 0; border: 0; border-radius: 12px; background: none; color: #aab0c0; font: 500 13px/1.2 'Kanit', sans-serif; cursor: pointer; }
    .tabbar svg { width: 22px; height: 22px; }
    .tabbar [aria-current] { color: #ff9a5c; background: rgba(234, 88, 12, .16); }

    /* เมนูทั้งหมด */
    .m-sheet[open] { display: block; position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; max-height: 85dvh; margin: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; border: 0; border-radius: 22px 22px 0 0; background: #14161f; color: #f3f4f6; animation: m-up .2s ease-out; }
    .m-sheet::backdrop { background: rgba(0, 0, 0, .65); }
    .m-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 18px; font-weight: 600; }
    .m-sheet-head button { min-height: 44px; padding: 0 16px; border-radius: 12px; background: #242838; font-size: 15px; }
    .m-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .m-menu a { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 14px; border-radius: 14px; background: #1f2331; font-size: 15px; font-weight: 500; line-height: 1.3; }
    .m-menu a svg { flex: none; width: 20px; height: 20px; color: #ff9a5c; }
    .m-menu a[aria-current] { background: rgba(234, 88, 12, .25); }
    .m-menu a.danger, .m-menu a.danger svg { color: #ff8f85; }
}
@keyframes m-up { from { transform: translateY(40px); opacity: .4; } }

@media (max-width: 767px) {
    .m-only { display: block; }
    .m-hide { display: none !important; }

    /* ตัวหนังสืออ่านง่าย และช่องกรอก 16px (กัน iPhone ซูมเอง) */
    body .text-xs { font-size: 14px; line-height: 1.55; }
    body .text-\[9px\], body .text-\[10px\], body .text-\[11px\] { font-size: 13px; line-height: 1.5; }
    body input:not([type=checkbox]), body select, body textarea { font-size: 16px !important; min-height: 48px; }
    body input[type=checkbox] { width: 22px; height: 22px; flex: none; }
    body main { padding-top: 16px; padding-bottom: 12px; }
    body main button, body main a[class*="rounded-xl"], body [id$="Modal"] button { min-height: 44px; }
    body main .chik-card:hover, body main .banner-card:hover, body main .tier-card:hover { transform: none; }
    body main h1 { font-size: 24px !important; line-height: 1.35; }

    /* หน้าแรก */
    .home-hero { display: flex; flex-direction: column; text-align: center; }
    .home-hero img.site-logo { width: 100%; max-width: 100%; max-height: 150px; }
    .home-hero .home-contact { justify-content: center; }
    .home-hero .home-ip > * { width: 100%; min-height: 48px; justify-content: center; font-size: 15px; }
    .m-cta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .m-cta a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px; border-radius: 16px; font-size: 17px; font-weight: 600; background: #ea580c; color: #fff; }
    .m-cta a + a { background: #242838; }

    body main a[href="news.php"] { min-height: 44px; }

    /* ร้านค้า */
    .banner-card.cat-card { height: 132px !important; }
    .banner-card.cat-card > div { padding: 16px; }
    .banner-card.cat-banner { height: 84px !important; border-radius: 18px; }
    .banner-card.cat-banner > div { padding: 14px 16px; }
    .sub-pills { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .sub-pills a { display: flex; align-items: center; flex: none; }
    .product-card { padding: 12px !important; }
    .product-card .product-img { height: 96px; margin: 4px 0; }
    .product-card .product-img img { max-height: 90px !important; }
    .product-card h3 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; min-height: 43px; overflow: hidden; white-space: normal; font-size: 14px; line-height: 1.5; }
    .product-card button { font-size: 16px; }

    /* ป๊อปอัปทุกอันเลื่อนขึ้นจากล่าง กดถึงด้วยนิ้วโป้ง */
    #buyConfirmModal, #redeemModal, #chikResultModal, #topupResultModal, #redeemResultModal { align-items: flex-end; padding: 0; backdrop-filter: none; }
    #buyConfirmModal > div, #redeemModal > div, #chikResultModal > div, #topupResultModal > div, #redeemResultModal > div { max-width: none; max-height: 92dvh; overflow-y: auto; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 24px 24px 0 0; background: #14161f; animation: m-up .2s ease-out; }
    body [id$="Modal"] button { min-height: 50px; font-size: 16px; }
    #btnMinus, #btnPlus { width: 56px; font-size: 24px !important; border-radius: 14px; }
    #buyAmountInput { width: 90px; height: 50px; font-size: 20px !important; border-radius: 14px; }
    #modalItemTitle { font-size: 17px; } #modalTotalPrice { font-size: 22px; }

    /* เติมเงิน */
    #tabPromptpay, #tabTruemoney { flex: 1; justify-content: center; padding-left: 8px; padding-right: 8px; line-height: 1.3; }
    .topup-tabs { width: 100%; gap: 6px; }
    #promptpayForm .grid button { min-height: 48px; font-size: 16px; }
    #btnSubmitPP, #btnSubmitVoucher, #btnSubmitCode { min-height: 54px; font-size: 16px; }
    #qrImageWrapper img { width: min(64vw, 260px); height: min(64vw, 260px); }

    /* ประวัติในโปรไฟล์: ตารางเป็นการ์ด */
    .history-card { padding: 4px 16px; }
    .history-card table, .history-card tbody { display: block; }
    .history-card thead { display: none; }
    .history-card tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 14px 0; }
    .history-card td { padding: 0; }
    .history-card td:first-child { flex: 1 1 100%; font-size: 15px; overflow-wrap: anywhere; }
    .history-card td.wide { flex: 1 1 100%; font-family: inherit; font-size: 13px; overflow-wrap: anywhere; }
    .history-card td:last-child { margin-left: auto; }
    .history-card td[colspan] { padding: 28px 0; }
    .profile-tabs a { flex: 1; justify-content: center; padding-left: 8px; padding-right: 8px; }

    /* กฎ / ผู้สนับสนุน / ท้ายเว็บ */
    body main .pl-11 { padding-left: 0; }
    .donate-page { row-gap: 0; } .donate-page > * + * { margin-top: 24px !important; }
    .tier-card { width: calc(50% - 6px) !important; padding: 16px 10px !important; } .tier-list { gap: 12px; }
    footer.w-full { padding: 12px 12px 8px; }
}
@media (prefers-reduced-motion: reduce) { .m-sheet, [id$="Modal"] > div { animation: none !important; } }
