/* =============================================================================
   shop-themes.css
   Theme overrides + dark-mode readability
   --------------------------------------------------------------------
   ใช้ CSS variables ที่ inject จาก _Layout.cshtml :
     --shop-bg, --shop-surface, --shop-ink, --shop-sub,
     --shop-primary, --shop-secondary, --shop-border, --shop-muted,
     --shop-on-primary  (text สี contrast กับ primary — dark/light)
   --------------------------------------------------------------------
   class flow:
     body.shop-themed       = ทุกหน้า /shop (apply เสมอ)
     body.theme-<key>       = theme key (sakura, mint, charcoal, ...)
     body.theme-dark        = themes ดาร์ก (indigo, cyber, charcoal)
   ============================================================================= */

body.shop-themed { background: var(--shop-bg) !important; color: var(--shop-ink); }
body.shop-themed footer { background: var(--shop-surface) !important; color: var(--shop-sub); border-top: 1px solid var(--shop-border); }
body.shop-themed a { color: var(--shop-primary); }
body.shop-themed a:hover { color: var(--shop-secondary); }

/* Bootstrap button overrides */
body.shop-themed .btn-primary,
body.shop-themed .btn-success,
body.shop-themed .btn-warning {
    background: var(--shop-primary) !important;
    border-color: var(--shop-primary) !important;
    color: var(--shop-on-primary) !important;
}
body.shop-themed .btn-primary:hover,
body.shop-themed .btn-success:hover,
body.shop-themed .btn-warning:hover { background: var(--shop-secondary) !important; border-color: var(--shop-secondary) !important; }
body.shop-themed .btn-outline-primary,
body.shop-themed .btn-outline-secondary,
body.shop-themed .btn-outline-success {
    color: var(--shop-primary) !important;
    border-color: var(--shop-primary) !important;
    background: transparent !important;
}
body.shop-themed .btn-outline-primary:hover,
body.shop-themed .btn-outline-secondary:hover,
body.shop-themed .btn-outline-success:hover {
    background: var(--shop-primary) !important;
    color: var(--shop-on-primary) !important;
}

/* Cards / panels */
body.shop-themed .card,
body.shop-themed .card-body {
    background: var(--shop-surface) !important;
    border-color: var(--shop-border) !important;
    color: var(--shop-ink) !important;
}
body.shop-themed .card .text-muted,
body.shop-themed .card small,
body.shop-themed .text-muted { color: var(--shop-sub) !important; }

/* Form controls */
body.shop-themed .form-control,
body.shop-themed .form-select {
    background: var(--shop-surface);
    border-color: var(--shop-border);
    color: var(--shop-ink);
}
body.shop-themed .form-control:focus,
body.shop-themed .form-select:focus { border-color: var(--shop-primary); box-shadow: 0 0 0 .15rem rgba(0,0,0,.06); }

/* Tables */
body.shop-themed .table { color: var(--shop-ink); }
body.shop-themed .table thead th { background: var(--shop-bg); color: var(--shop-sub); border-color: var(--shop-border); }
body.shop-themed .table tbody td { border-color: var(--shop-border); }

/* Badge variants */
body.shop-themed .badge.bg-primary { background: var(--shop-primary) !important; }
body.shop-themed .badge.bg-success { background: var(--shop-secondary) !important; }

/* Top nav (.fixed-top) — keep readable on dark themes */
body.shop-themed.theme-dark nav.fixed-top { background-color: var(--shop-surface) !important; background-image: none !important; }
body.shop-themed.theme-dark nav.fixed-top a,
body.shop-themed.theme-dark nav.fixed-top span,
body.shop-themed.theme-dark nav.fixed-top div { color: var(--shop-ink) !important; }

/* === Dark theme readability overrides ===
   Index/Category/Product views มี inline-style "color:Black", "color:dimgrey",
   "color:cadetblue", "background-color:whitesmoke" ฯลฯ ที่ไม่ได้รับ CSS vars
   ใช้ attribute selector + !important บังคับให้กลับด้านบน dark themes */
body.theme-dark { color: var(--shop-ink); }
body.theme-dark #productGrid .moreBox,
body.theme-dark #productGrid .moreBox h1,
body.theme-dark #productGrid .moreBox h2,
body.theme-dark #productGrid .moreBox h3,
body.theme-dark #productGrid .moreBox h4,
body.theme-dark #productGrid .moreBox h5,
body.theme-dark #productGrid .moreBox h6,
body.theme-dark #productGrid .moreBox p,
body.theme-dark #productGrid .moreBox span,
body.theme-dark #productGrid .moreBox div,
body.theme-dark #productGrid .moreBox a,
body.theme-dark #productGrid .moreBox b,
body.theme-dark #productGrid .moreBox label { color: var(--shop-ink) !important; }
/* override inline "color:Black/black" */
body.theme-dark [style*="color:Black"],
body.theme-dark [style*="color: Black"],
body.theme-dark [style*="color:black"],
body.theme-dark [style*="color: black"],
body.theme-dark [style*="color:#000"],
body.theme-dark [style*="color: #000"] { color: var(--shop-ink) !important; }
/* override "color:dimgrey/DimGray" */
body.theme-dark [style*="color:dimgrey"],
body.theme-dark [style*="color: dimgrey"],
body.theme-dark [style*="color:DimGray"],
body.theme-dark [style*="color:DimGrey"],
body.theme-dark [style*="color:dimgray"] { color: var(--shop-sub) !important; }
/* override "color:cadetblue" → ใช้ secondary (มักเป็น lighter accent) */
body.theme-dark [style*="color:cadetblue"],
body.theme-dark [style*="color: cadetblue"],
body.theme-dark [style*="color:CadetBlue"] { color: var(--shop-secondary) !important; }
/* override "background-color:whitesmoke" บน <select> และ <input> */
body.theme-dark [style*="background-color:whitesmoke"],
body.theme-dark [style*="background: whitesmoke"],
body.theme-dark [style*="background-color:WhiteSmoke"],
body.theme-dark [style*="background:#f5f5f5"] {
    background-color: var(--shop-surface) !important;
    color: var(--shop-ink) !important;
}
/* override "background-color:white"/"#fff" บน element (ไม่เอา .moreBox เพราะ surface ตั้งไว้แล้ว) */
body.theme-dark [style*="background-color:white"]:not(.moreBox),
body.theme-dark [style*="background: white"]:not(.moreBox),
body.theme-dark [style*="background-color:#fff"]:not(.moreBox),
body.theme-dark [style*="background-color: #fff"]:not(.moreBox),
body.theme-dark [style*="background-color:#FFF"]:not(.moreBox) {
    background-color: var(--shop-surface) !important;
    color: var(--shop-ink) !important;
}
/* Bootstrap form-control / form-select บน dark theme */
body.theme-dark select,
body.theme-dark input[type=text],
body.theme-dark input[type=number],
body.theme-dark input[type=email],
body.theme-dark input[type=tel],
body.theme-dark input[type=password],
body.theme-dark input[type=search],
body.theme-dark textarea,
body.theme-dark .form-select,
body.theme-dark .form-control,
body.theme-dark .form-select-sm {
    background-color: var(--shop-surface) !important;
    color: var(--shop-ink) !important;
    border-color: var(--shop-border) !important;
}
body.theme-dark select option { background: var(--shop-surface); color: var(--shop-ink); }

/* Brand-hashtag images (พื้นหลังโปร่งใส) — ปรับ contrast ให้ดูชัดบน dark */
body.theme-dark .brand-hashtag-first .brand-hashtag,
body.theme-dark .brand-hashtag-second .brand-hashtag,
body.theme-dark .subbrand-hashtag { filter: brightness(1.05) drop-shadow(0 0 6px rgba(255,255,255,.05)); }

/* dark theme — link color สว่างขึ้น */
body.theme-dark a { color: var(--shop-secondary); }
body.theme-dark a:hover { color: var(--shop-primary); }

/* Footer dark */
body.theme-dark footer { background: var(--shop-surface) !important; color: var(--shop-sub) !important; }
body.theme-dark footer a, body.theme-dark footer span, body.theme-dark footer div { color: var(--shop-sub) !important; }

/* Carousel indicators tinted */
body.shop-themed .carousel-indicators button { background-color: var(--shop-primary); }

/* Generic accent helpers */
body.shop-themed .text-primary { color: var(--shop-primary) !important; }
body.shop-themed .text-success { color: var(--shop-secondary) !important; }
body.shop-themed .bg-primary { background: var(--shop-primary) !important; }
body.shop-themed .bg-light { background: var(--shop-surface) !important; }

/* =============================================================================
   Mobile readability (Shopee-like sizing สำหรับ viewport scale=1)
   --------------------------------------------------------------------
   ใช้ !important เพื่อ override inline style ใน _ProductCard.cshtml
   ============================================================================= */
/* Top nav (fixed-top) — mobile + tablet (Bootstrap < lg)
   ครอบทั้ง iPhone, iPad portrait และ desktop หน้าต่างเล็ก ≈ 600-991px */
@media (max-width: 991.98px) {
    nav.fixed-top a.nav-link[style*="font-size:small"] {
        font-size: 14px !important;
        height: 38px !important;
        padding-top: 6px !important;
        font-weight: 400 !important;
    }
    nav.fixed-top a.nav-link img#Logout,
    nav.fixed-top a.nav-link img#Favorite { height: 18px !important; }
    nav.fixed-top a.nav-link img#Cart_All { height: 20px !important; }
    nav.fixed-top .fav-badge,
    nav.fixed-top .cart-badge {
        font-size: 11px !important;
        padding: 2px 5px !important;
        min-width: 16px !important;
        top: -7px !important;
        right: -12px !important;
    }
}
@media (max-width: 575.98px) {
    /* mobile — phone portrait */
    nav.fixed-top a.nav-link[style*="font-size:small"] {
        font-size: 15px !important;
        height: 40px !important;
        padding-top: 8px !important;
    }
    nav.fixed-top a.nav-link img#Logout,
    nav.fixed-top a.nav-link img#Favorite { height: 20px !important; }
    nav.fixed-top a.nav-link img#Cart_All { height: 22px !important; }

    /* default productView */
    .moreBox h6.productView {
        font-size: 14px !important;
        line-height: 1.45 !important;
    }
    /* ชื่อสินค้า (อยู่ใน a แรกของ card) — เด่นสุด */
    .moreBox > a:first-of-type h6.productView {
        font-size: 16px !important;
        font-weight: 600 !important;
        line-height: 1.3 !important;
        padding-top: 6px !important;
    }
    /* ราคา (มี price tag icon นำหน้า) — bold เน้น */
    .moreBox .row h6.productView img[src*="PriceTag"] { height: 16px !important; }
    .moreBox .row h6.productView[style*="color:Black"] {
        font-size: 17px !important;
        font-weight: 700 !important;
    }
    /* sub info — ขายแล้ว / Stock เหลือ (สีเทา/เทาฟ้า) */
    .moreBox .row h6.productView[style*="dimgrey"],
    .moreBox .row h6.productView[style*="cadetblue"] {
        font-size: 12px !important;
        font-weight: 500 !important;
    }
    .moreBox .row h6.productView img { height: 14px !important; }
    /* qty + unit dropdown — touch-friendly */
    .moreBox .select-qty,
    .moreBox .select-unit {
        height: 38px !important;
        font-size: 14px !important;
        font-weight: 500 !important;
    }
    /* ปุ่ม Favorite + Add-to-cart คุมด้วย .card-actions (ดูส่วนล่าง) — mobile ปรับผ่านตัวแปร --act-h */
    /* spacing ระหว่าง row ใน card — กันแน่นเกิน */
    .moreBox .row + .row { margin-top: 4px; }
}

/* แท็บเล็ตขนาดเล็ก (576-767) — กลางๆ ระหว่าง mobile กับ desktop */
@media (min-width: 576px) and (max-width: 767.98px) {
    .moreBox h6.productView { font-size: 13px !important; line-height: 1.4 !important; }
    .moreBox > a:first-of-type h6.productView { font-size: 15px !important; font-weight: 600 !important; }
    .moreBox .row h6.productView[style*="color:Black"] { font-size: 16px !important; font-weight: 700 !important; }
    .moreBox .row h6.productView[style*="dimgrey"],
    .moreBox .row h6.productView[style*="cadetblue"] { font-size: 12px !important; }
    .moreBox .select-qty,
    .moreBox .select-unit { height: 36px !important; font-size: 13px !important; }
    /* ปุ่ม Favorite + Add-to-cart คุมด้วย .card-actions (ดูส่วนล่าง) */
}

/* =============================================================================
   Card action row — ปุ่ม Favorite + Add-to-cart (ท้ายการ์ดสินค้า)
   จัดให้ "สูงเท่ากัน + ต่อกัน" เป็นแถวเดียว เนียนทุกจอ (desktop = mobile ระบบเดียว)
   ใช้ CSS background แทนรูป Cart_Background.png (พื้นแดงล้วน) → คมชัดทุกความกว้าง
   ปรับความสูงร่วมทั้งแถวผ่านตัวแปร --act-h ตัวเดียว
   ============================================================================= */
.moreBox .card-actions {
    --act-h: 38px;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch;
    gap: 6px;
    margin: 10px 0 2px !important;
    padding: 0 2px;
}
/* ล้าง gutter/width ที่ Bootstrap .row > * ยัดให้ลูกทุกตัว (ไม่งั้น fav เยื้อง + ปุ่มตกบรรทัด) */
.moreBox .card-actions > * {
    padding: 0 !important;
    margin-top: 0 !important;
    width: auto;
    max-width: none;
}
.moreBox .card-actions .card-fav {
    flex: 0 0 auto;
    width: calc(var(--act-h) + 6px);
    height: var(--act-h);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--shop-surface, #fff);
    border: 1px solid var(--shop-border, #e2e8f0);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.moreBox .card-actions .card-fav:hover { border-color: #e11d48; background: rgba(225,29,72,.06); }
.moreBox .card-actions .card-fav .add-to-favorite {
    height: calc(var(--act-h) - 14px);
    display: block;
    cursor: pointer;
}
.moreBox .card-actions .card-cart {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
}
.moreBox .card-actions .add-cart-link { display: block; text-decoration: none; }
.moreBox .card-actions .add-cart-btn {
    height: var(--act-h);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 10px;
    background: linear-gradient(135deg, #fb4b43, #ef3b32);
    color: #fff !important;
    font-weight: 700;
    font-size: 14px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    box-shadow: 0 3px 8px rgba(239,59,50,.26);
    transition: filter .15s ease, transform .05s ease;
}
.moreBox .card-actions .add-cart-btn:hover { filter: brightness(1.05); }
.moreBox .card-actions .add-cart-btn:active { transform: translateY(1px); }
.moreBox .card-actions .add-cart-btn img { height: 20px; flex: 0 0 auto; }
.moreBox .card-actions .add-cart-txt-short { display: none; }

/* จอแคบ (2 คอลัมน์) — ปุ่มสูงขึ้นนิด กดง่าย + ใช้ข้อความสั้น "ใส่ตะกร้า" ไม่ให้ล้นปุ่มแคบ */
@media (max-width: 575.98px) {
    .moreBox .card-actions { --act-h: 42px; gap: 5px; }
    .moreBox .card-actions .add-cart-btn { font-size: 13px; gap: 5px; }
    .moreBox .card-actions .add-cart-btn img { height: 18px; }
    .moreBox .card-actions .add-cart-txt-full  { display: none; }
    .moreBox .card-actions .add-cart-txt-short { display: inline; }
}
/* แท็บเล็ตเล็ก (3 คอลัมน์) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .moreBox .card-actions { --act-h: 40px; }
    .moreBox .card-actions .add-cart-btn { font-size: 13px; }
}

/* =============================================================================
   เทมเพลตเลย์เอาต์ (ShopTemplateProvider) — อ่าน var(--tpl-*) จาก :root (inject ใน _Layout)
   มือถือ 2 คอล · แท็บเล็ต 3 คอล · desktop (≥1001px) = ตาม template
   โครงภายใน Card สินค้า (#divProduct/.moreBox) คงเดิม — เปลี่ยนแค่ กรอบ/เงา/มุม/พื้น/คอลัมน์/ระยะ
   gap ทำด้วย margin (เฉพาะ #divProduct) ไม่กระทบ banner คั่น / brand hashtag ที่ปนใน grid
   ============================================================================= */
/* CSS Grid auto-fill — responsive ตามจอ: การ์ดมี min-width · จอใหญ่ = คอลัมน์มากขึ้นเอง
   min(--tpl-min, 46%) → มือถือคง 2 คอลัมน์เสมอ · desktop/1920 = ตาม min-width */
body.tpl #productGrid,
body.tpl #productSubGrid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(min(var(--tpl-min, 300px), 46%), 1fr));
    gap: var(--tpl-gap, 14px);
    max-width: var(--tpl-container, 100%);
    margin-left: auto !important;
    margin-right: auto !important;
    align-items: stretch; /* การ์ดในแถวเดียวกันสูงเท่ากัน (ปุ่มล่างตรงแนว) */
}
/* banner คั่น / brand hashtag / อื่น ๆ ที่ไม่ใช่การ์ดสินค้า → เต็มแถว (ยกเว้น skeleton placeholder) */
body.tpl #productGrid > *:not(#divProduct):not(.skeleton-card),
body.tpl #productSubGrid > *:not(#divProduct):not(.skeleton-card) { grid-column: 1 / -1; }
/* skeleton placeholder = grid cell เหมือนการ์ด (กันแสดงแถวละ 1 ตอนรอโหลด) */
body.tpl #productGrid > .skeleton-card,
body.tpl #productSubGrid > .skeleton-card { width: auto !important; margin: 0 !important; }

/* การ์ดสินค้า = cell + frame (โครงภายในคงเดิม) · scope เฉพาะลูกของ grid เท่านั้น
   กัน #divProduct ที่อยู่นอก grid (เช่นในหน้า/ส่วนอื่น) โดน width:auto จนเพี้ยน */
body.tpl #productGrid > #divProduct,
body.tpl #productSubGrid > #divProduct {
    width: auto !important;
    margin: 0 !important;
    box-sizing: border-box;
    height: auto;
    border-radius: var(--tpl-card-radius, 8px);
    background: var(--tpl-card-bg, transparent);
    box-shadow: var(--tpl-card-shadow, none);
    border: var(--tpl-card-border, none);
    padding: var(--tpl-card-pad, 8px);
    overflow: hidden;
    transition: box-shadow .18s ease, transform .18s ease;
    /* flex column → ดันแถวปุ่มไปชิดล่าง ให้ตรงแนวกันทุกใบเมื่อการ์ดสูงเท่ากัน */
    display: flex;
    flex-direction: column;
}
body.tpl #productGrid > #divProduct:hover,
body.tpl #productSubGrid > #divProduct:hover { transform: translateY(-2px); }
/* รูปสินค้าไม่ถูกบีบเมื่อการ์ดยืดสูง */
body.tpl #productGrid > #divProduct > .ratio,
body.tpl #productSubGrid > #divProduct > .ratio { flex-shrink: 0; }
/* แถวปุ่ม Favorite + ตะกร้า = ชิดล่างสุดของการ์ด (margin-top:auto กินช่องว่างที่เหลือ) */
body.tpl #productGrid > #divProduct .card-actions,
body.tpl #productSubGrid > #divProduct .card-actions { margin-top: auto !important; padding-top: 8px; }

/* พื้นหลังหน้า (variant ที่ทำด้วย var ตรง ๆ ไม่ได้) */
body.tpl.tpl-bg-soft { background: color-mix(in srgb, var(--shop-bg) 65%, var(--shop-surface)) !important; }
body.tpl.tpl-bg-tint { background: color-mix(in srgb, var(--shop-primary) 6%, var(--shop-bg)) !important; }

/* Hero / Banner */
body.tpl-hero-boxed .banner-slot,
body.tpl-hero-framed .banner-slot { border-radius: 14px; overflow: hidden; }
body.tpl-hero-framed .banner-slot { box-shadow: 0 8px 24px -10px rgba(40,30,15,.25); }
body.tpl-hero-minimal .banner-slot { border-radius: 0; }
