/* ============================================================================
   ตัวเลือกภาษา — dropdown ที่วาดเอง แทน <select> ของระบบ

   ใช้ทั้งหน้าแรก (ที่ไม่มี Tailwind) และหน้าสมาชิก จึงเขียนเป็น CSS ล้วนและ
   ใส่สีเป็น hex ตรง ๆ ไม่พึ่ง custom property ของธีมใดธีมหนึ่ง เพราะสองฝั่ง
   ประกาศตัวแปรคนละชุดกัน

   โครงเป็น <details>/<summary> จึงเปิด-ปิดและใช้คีย์บอร์ดได้โดยไม่ต้องมี JS
   (JS ใน partials/flags.php เติมแค่ "คลิกที่อื่นแล้วปิด")
   ========================================================================= */

.langsel {
    position: relative;
    display: inline-block;
    font-family: 'Space Grotesk', 'Noto Sans Thai', 'Noto Sans SC', sans-serif;
}

/* ---- ปุ่ม ---- */
.langsel-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid rgba(212, 175, 55, 0.24);
    border-radius: 2px;
    background: rgba(18, 24, 15, 0.75);
    color: #eef3ec;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .2s ease, background-color .2s ease, color .2s ease;
    /* ลูกศรสามเหลี่ยมของ <summary> ต้องถูกถอดออกทั้งสองเอนจิน */
    list-style: none;
    -webkit-tap-highlight-color: transparent;
}
.langsel-btn::-webkit-details-marker { display: none; }
.langsel-btn::marker { content: ''; }

.langsel-btn:hover {
    border-color: rgba(212, 175, 55, 0.55);
    background: rgba(212, 175, 55, 0.08);
    color: #ffd966;
}
.langsel-btn:focus-visible {
    outline: none;
    border-color: #e8b931;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.28);
}
.langsel[open] > .langsel-btn {
    border-color: rgba(212, 175, 55, 0.55);
    color: #ffd966;
}

/* ---- ธง ---- */
.langsel-flag {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    border-radius: 50%;
    overflow: hidden;               /* กลมด้วย CSS จะได้ไม่ต้องมี clipPath ใน SVG */
    display: block;
    /* ขอบในบาง ๆ กันธงพื้นขาว/แดงเข้มกลืนไปกับพื้นหลัง */
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22), 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ---- ลูกศร ---- */
.langsel-caret {
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    opacity: .55;
    transition: transform .2s ease, opacity .2s ease;
}
.langsel[open] .langsel-caret { transform: rotate(180deg); opacity: .9; }

/* ---- เมนู ---- */
.langsel-menu {
    position: absolute;
    z-index: 60;
    top: calc(100% + 6px);
    right: 0;
    /* วิดเจ็ตนี้ถูกวางในสองสไตล์ชีตที่คุมกันคนละแบบ จึงตั้งค่าที่หน้าอื่นอาจเผลอ
       ทับไว้ให้ครบ (หน้าแรกมี `nav{display:flex;max-width:1180px;padding:16px 32px}`
       แบบไม่ผูกคลาส ซึ่งเคยทำให้เมนูนี้เรียงเป็นแนวนอนเต็มจอมาแล้ว) */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    max-width: none;
    width: max-content;
    min-width: 178px;
    margin: 0;
    padding: 5px;
    border: 1px solid rgba(212, 175, 55, 0.24);
    border-radius: 2px;
    /* ทึบแสง: เมนูนี้ลอยทับเนื้อหาที่มีทั้งรูปและตาราง โปร่งแล้วอ่านไม่ออก */
    background: #0b2612;
    box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .85), 0 0 0 1px rgba(0, 0, 0, .35);
    animation: langsel-in .16s ease-out;
}
/* กางขึ้น/ชิดซ้าย — ตั้งมาจาก PHP (--up/--left) หรือ JS วัดที่ว่างแล้วพลิกให้เอง (--auto-*) */
.langsel--up .langsel-menu,
.langsel--auto-up .langsel-menu { top: auto; bottom: calc(100% + 6px); }
.langsel--left .langsel-menu,
.langsel--auto-left .langsel-menu { right: auto; left: 0; }

@keyframes langsel-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.langsel--up .langsel-menu,
.langsel--auto-up .langsel-menu { animation-name: langsel-in-up; }
@keyframes langsel-in-up {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .langsel-menu { animation: none; }
    .langsel-caret { transition: none; }
}

/* ---- รายการภาษา ---- */
.langsel-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 2px;
    color: rgba(242, 237, 224, 0.72);
    font-size: 13.5px;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}
.langsel-opt:hover {
    background: rgba(212, 175, 55, 0.10);
    color: #ffd966;
}
.langsel-opt:focus-visible {
    outline: none;
    background: rgba(212, 175, 55, 0.14);
    color: #ffd966;
}
.langsel-opt-name { flex: 1 1 auto; }

.langsel-opt.is-active {
    color: #ffd966;
    background: rgba(212, 175, 55, 0.07);
}
.langsel-check {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    opacity: 0;                     /* จองที่ไว้เสมอ ข้อความจะได้ไม่ขยับตอนสลับภาษา */
    color: #e8b931;
}
.langsel-opt.is-active .langsel-check { opacity: 1; }

/* ---- หน้าแรกใช้มุมคม ให้เข้ากับปุ่มอื่นในแถบเมนูของ template ---- */
.langsel--sharp .langsel-btn,
.langsel--sharp .langsel-menu { border-radius: 2px; }
.langsel--sharp .langsel-opt  { border-radius: 1px; }

@media (max-width: 860px) {
    .langsel-btn { padding: 6px 8px; font-size: 12px; gap: 6px; }
    .langsel-flag { width: 18px; height: 18px; flex-basis: 18px; }
    /* จอแคบมากเหลือแค่ธง ชื่อภาษาไปโผล่ในเมนูแทน */
    .langsel--compact .langsel-btn .langsel-name { display: none; }
}
