/* ══════════════════════════════════════════════════════════════════════════════
   checkbox / radio กลางของทั้งเว็บ (26 ต.ค. 69) — หน้าตาเดียวกันทุกหน้า ทุกเบราว์เซอร์
   style.css ดึงไฟล์นี้ให้ทุกหน้าหลังร้าน ; หน้าที่ไม่ใช้ style.css (superadmin, login) ใส่ <link> เอง

   ใช้ครั้งถัดไป: เขียน <input type="checkbox"> / <input type="radio"> เฉย ๆ ได้หน้าตานี้เลย
     ห้ามตั้ง width / height / accent-color / border ให้ checkbox ในหน้าเอง (ทำให้แต่ละหน้าไม่เหมือนกัน)
     ต้องการขนาดใหญ่ (ตาราง/การ์ดที่กดบ่อย) ใส่ class="ck-lg"
     สวิตช์เปิด-ปิด ใช้ .toggle-switch (ซ่อน checkbox ไว้ข้างใน — ไม่โดนกฎนี้)
     ชิปติ๊กเลือก ใช้ .chip-check (style.css) ; checkbox ที่ต้องการหน้าตาตั้งต้นของเบราว์เซอร์ ใส่ class="ck-native"

   ทำไมต้องเจาะจงสูง (:not(#ck)): หลายหน้ามีกฎกล่องฟอร์มแบบ ".xxx input{width:100%;border:...}"
   ที่เผลอไปโดน checkbox ในกล่องเดียวกัน ทำให้ checkbox ยืดเต็มบรรทัด/มีกรอบช่องกรอก
   ส่วน display / margin อยู่ในกฎเจาะจงต่ำ (:where) — กฎของหน้าที่ซ่อน (display:none) หรือขยับให้ตรงบรรทัดยังชนะได้
   ══════════════════════════════════════════════════════════════════════════════ */
:root {
    --ck-accent: #7DCB4B;
    --ck-accent-hover: #6ab83a;
    --ck-border: #b8c2cf;
    --ck-bg: #fff;
    --ck-mark: #fff;
    --ck-focus: rgba(125, 203, 75, .35);
}
html.dark-mode {
    --ck-border: #4b5563;
    --ck-bg: #111827;
}

/* ตัวกล่อง */
:where(input[type=checkbox], input[type=radio]) { display: inline-grid; place-content: center; margin: 0; vertical-align: middle; flex-shrink: 0; }
input:is([type=checkbox], [type=radio]):not(#ck):not(.ck-native):not(.toggle-switch input):not(.theme-switch input):not(.switch input):not(.tg-toggle input) {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    min-width: 18px;
    padding: 0;
    border: 2px solid var(--ck-border);
    background: var(--ck-bg);
    box-shadow: none;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
input[type=checkbox]:not(#ck):not(.ck-native) { border-radius: 5px; }
input[type=radio]:not(#ck):not(.ck-native) { border-radius: 50%; }

/* เครื่องหมายข้างใน: ติ๊ก (checkbox) / จุด (radio) */
input[type=checkbox]:not(.ck-native)::before {
    content: '';
    width: 10px;
    height: 10px;
    background: var(--ck-mark);
    clip-path: polygon(14% 44%, 0 59%, 40% 100%, 100% 22%, 86% 8%, 40% 70%);
    transform: scale(0);
    transition: transform .12s ease-in-out;
}
input[type=radio]:not(.ck-native)::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ck-mark);
    transform: scale(0);
    transition: transform .12s ease-in-out;
}
input:is([type=checkbox], [type=radio]):not(.ck-native):checked::before { transform: scale(1); }
/* ติ๊กบางส่วน (เลือกบางรายการในกลุ่ม) — ขีดกลาง */
input[type=checkbox]:not(.ck-native):indeterminate::before { clip-path: none; height: 2px; border-radius: 1px; transform: scale(1); }

/* สถานะ — :not(#ck):not(#ck2) ให้ชนะกฎตัวกล่องด้านบน (ที่มี :not(สวิตช์...) หลายชั้นจนเจาะจงสูง) */
input:is([type=checkbox], [type=radio]):not(#ck):not(#ck2):not(.ck-native):is(:checked, [type=checkbox]:indeterminate) { background: var(--ck-accent); border-color: var(--ck-accent); }
input:is([type=checkbox], [type=radio]):not(#ck):not(#ck2):not(.ck-native):hover:not(:disabled) { border-color: var(--ck-accent); }
input:is([type=checkbox], [type=radio]):not(#ck):not(#ck2):not(.ck-native):is(:checked, [type=checkbox]:indeterminate):hover:not(:disabled) { background: var(--ck-accent-hover); border-color: var(--ck-accent-hover); }
input:is([type=checkbox], [type=radio]):not(#ck):not(#ck2):not(.ck-native):focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ck-focus); }
input:is([type=checkbox], [type=radio]):not(#ck):not(#ck2):not(.ck-native):disabled { cursor: not-allowed; opacity: .5; }

/* ขนาดใหญ่ — ตารางสิทธิ์ / รายการที่กดบ่อยบนแท็บเล็ต */
input:is([type=checkbox], [type=radio]).ck-lg:not(#ck):not(#ck2) { width: 22px; height: 22px; min-width: 22px; }
input[type=checkbox].ck-lg::before { width: 13px; height: 13px; }
input[type=radio].ck-lg::before { width: 10px; height: 10px; }

/* checkbox/radio คู่กับข้อความ — ใช้ class นี้กับ <label> ได้เลย */
.ck-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

@media (prefers-reduced-motion: reduce) {
    input:is([type=checkbox], [type=radio])::before, input:is([type=checkbox], [type=radio]) { transition: none; }
}
