/*
 * DongChat — ปรับหน้าตา Element Web ให้ใช้ได้ทุกจอ (มือถือ / แท็บเล็ต / คอม)
 * โหลดผ่าน generated/index.html (scripts/render-config.sh ฉีด <link> ให้)
 *
 * ⚠ อิงชื่อ class ของ Element Web (mx_*) — เมื่ออัปเดตเวอร์ชัน Element ให้เปิดเว็บที่ความกว้าง 390 / 820 / 1280
 *   แล้วตรวจว่ายังใช้ได้ (ดู README หัวข้อ "รองรับทุกจอ")
 *
 *   มือถือ   < 768px  : แสดงทีละหน้าแบบแอปแชท (รายการห้อง ↔ ห้อง) + ปุ่มย้อนกลับ, แผงข้อมูลห้องเต็มจอ
 *   แท็บเล็ต 768–1199 : 2 คอลัมน์, แผงข้อมูลห้องลอยทับด้านขวา
 *   คอม     ≥ 1200px  : layout ปกติของ Element + ขัดเกลาเล็กน้อย
 */

/* ---------- ทุกจอ ---------- */

:root,
[class*="cpd-theme"] {
    --dc-green: #2bb673;
    --dc-green-dark: #1a9a5c;
    --dc-font: "Inter", "Noto Sans Thai", "Noto Sans Thai UI", "Leelawadee UI", "Sukhumvit Set", "Thonburi",
        "Sarabun", Tahoma, system-ui, sans-serif;
    /* compound design tokens ของ Element: ฟอนต์ที่มีตัวไทยสวย ๆ (Inter ไม่มีตัวไทย → ตกไปตัวถัดไป) */
    --cpd-font-family-sans: var(--dc-font);
}

body,
.mx_MatrixChat_wrapper {
    font-family: var(--dc-font);
}

/* ความสูงตามจอจริงบนมือถือ (แถบที่อยู่ของเบราว์เซอร์ยืด/หด) */
html,
body,
#matrixchat {
    height: 100% !important;
    height: 100dvh !important;
}

/* ภาษาไทยมีสระบน/ล่าง — เพิ่มระยะบรรทัดในข้อความแชท อ่านง่ายขึ้น */
.mx_EventTile_body,
.mx_BasicMessageComposer_input {
    line-height: 1.6;
}

/* เมนูรูปโปรไฟล์: "ออกจากระบบ / สลับบัญชี" (dongchat.js) เป็นสีแดงแบบปุ่มอันตราย */
.dc-logout,
.dc-logout * {
    color: var(--cpd-color-text-critical-primary, #ff5c5c) !important;
}
.dc-logout svg {
    color: var(--cpd-color-icon-critical-primary, #ff5c5c) !important;
}

/* ปุ่มย้อนกลับ (dongchat.js ใส่ไว้ในหัวห้อง) — ซ่อนบนจอใหญ่ */
.dc-back {
    display: none;
}

/* ---------- หน้า login / welcome ---------- */

.mx_AuthPage {
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(43, 182, 115, 0.35), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(43, 182, 115, 0.25), transparent 60%),
        #0f1418 !important;
}

.mx_AuthPage_modal {
    border-radius: 20px !important;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45) !important;
}

.mx_AuthBody .mx_Field input,
.mx_AuthBody .mx_Field select {
    border-radius: 10px;
}

.mx_AuthBody .mx_Login_submit,
.mx_AuthBody button[type="submit"] {
    border-radius: 999px !important;
    min-height: 44px;
    font-weight: 600;
}

/* หน้า welcome / หน้าแรก (branding/welcome.html, home.html)
   Element sanitize หน้า embed: ตัดทั้ง <style> และ class ทิ้ง → เลือกตามโครงสร้างแทน */
.mx_WelcomePage_body > div {
    max-width: 420px;
    margin: 0 auto;
    padding: 24px 8px;
    text-align: center;
}
.mx_WelcomePage_body > div > img {
    width: 200px;
    max-width: 70%;
    height: auto;
    margin-bottom: 12px;
}
.mx_WelcomePage_body > div > h1 {
    font-size: 22px;
    line-height: 1.4;
    margin: 8px 0;
}
.mx_WelcomePage_body > div > p {
    margin: 8px 0;
    line-height: 1.6;
    opacity: 0.85;
}
.mx_WelcomePage_body a[href="#/login"] {
    display: block;
    margin: 20px auto 4px;
    max-width: 280px;
    padding: 13px 24px;
    border-radius: 999px;
    background: var(--dc-green);
    color: #fff !important;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none !important;
    box-shadow: 0 8px 24px rgba(43, 182, 115, 0.35);
    transition: transform 0.1s ease, background 0.2s ease;
}
.mx_WelcomePage_body a[href="#/login"]:hover {
    background: var(--dc-green-dark);
}
.mx_WelcomePage_body a[href="#/login"]:active {
    transform: scale(0.98);
}
.mx_WelcomePage_body > div > ul {
    list-style: none;
    text-align: left;
    margin: 24px auto 8px;
    padding: 14px 18px;
    line-height: 1.9;
    border-radius: 14px;
    background: rgba(127, 127, 127, 0.1);
}
.mx_WelcomePage_body > div > p:last-child {
    margin-top: 16px;
    font-size: 13px;
    opacity: 0.6;
}

.mx_HomePage_body > div {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 24px;
    line-height: 1.65;
}
.mx_HomePage_body > div > h1 {
    font-size: 24px;
    margin: 0 0 4px;
}
.mx_HomePage_body > div > h2 {
    font-size: 17px;
    margin: 28px 0 8px;
    color: var(--dc-green);
}
.mx_HomePage_body > div > h1 + p,
.mx_HomePage_body > div > ol + p {
    opacity: 0.7;
    margin: 0 0 8px;
}
.mx_HomePage_body ol,
.mx_HomePage_body ul {
    padding-left: 22px;
    margin: 6px 0;
}
.mx_HomePage_body li {
    margin: 3px 0;
}
/* กล่องเตือน Recovery key */
.mx_HomePage_body > div > div:has(> ul) {
    border: 1px solid #e0a030;
    background: rgba(224, 160, 48, 0.08);
    border-radius: 14px;
    padding: 12px 16px;
    margin: 12px 0;
}
.mx_HomePage_body code {
    background: rgba(127, 127, 127, 0.15);
    padding: 1px 5px;
    border-radius: 4px;
    word-break: break-word;
}
/* ปุ่ม "เริ่มแชทใหม่" / "สร้างห้องกลุ่ม" */
.mx_HomePage_body > div > div > a[href^="#/"] {
    display: inline-block;
    margin: 8px 8px 4px 0;
    padding: 10px 20px;
    border-radius: 999px;
    background: var(--dc-green);
    color: #fff !important;
    text-decoration: none !important;
    font-weight: 600;
}

/* ซ่อน "Powered by Matrix" / ลิงก์ footer ของ Element */
.mx_AuthFooter {
    display: none !important;
}

/* ---------- จอสัมผัส: เป้ากดใหญ่ขึ้น ---------- */

@media (pointer: coarse) {
    .mx_RoomListItemView {
        min-height: 56px !important;
    }
    .mx_MessageComposer_button,
    .mx_RoomHeader button {
        min-width: 40px;
        min-height: 40px;
    }
}

/* ---------- แท็บเล็ต + มือถือ: แผงข้อมูลห้องลอยทับ ไม่บีบไทม์ไลน์ ---------- */

@media (max-width: 1199px) {
    .mx_MainSplit {
        position: relative;
    }
    .mx_RightPanel_ResizeWrapper {
        position: absolute !important;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        width: min(380px, 92%) !important;
        max-width: none !important;
        box-shadow: -12px 0 32px rgba(0, 0, 0, 0.35);
    }
    .mx_RightPanel_ResizeWrapper .mx_RightPanel {
        width: 100% !important;
    }
}

/* ---------- มือถือ ---------- */

@media (max-width: 767px) {
    /* กันพื้นที่ notch / home indicator (index.html ตั้ง viewport-fit=cover) */
    .mx_MatrixChat_wrapper {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
            env(safe-area-inset-left);
        box-sizing: border-box;
    }

    /* ตัวอักษร < 16px ทำให้ iOS ซูมหน้าเองตอนแตะช่องพิมพ์ */
    input,
    textarea,
    select,
    .mx_BasicMessageComposer_input,
    [contenteditable="true"] {
        font-size: 16px !important;
    }

    /* เส้นแบ่งปรับขนาดคอลัมน์ ไม่ต้องใช้บนมือถือ */
    .mx_MatrixChat > div > .mx_Separator,
    .mx_MatrixChat > div > [role="separator"] {
        display: none !important;
    }

    /* หน้า "รายการห้อง": คอลัมน์รายการห้องเต็มจอ ซ่อนเนื้อหาหลัก */
    html[data-dc-view="list"] .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: none !important;
    }
    html[data-dc-view="list"] .mx_LeftPanel_outerWrapper,
    html[data-dc-view="list"] .mx_LeftPanel_wrapper,
    html[data-dc-view="list"] .mx_LeftPanel {
        width: 100% !important;
        max-width: none !important;
        flex: 1 1 auto !important;
    }
    html[data-dc-view="list"] .mx_MatrixChat > div > div:has(.mx_RoomView_wrapper) {
        display: none !important;
    }

    /* หน้า "ห้อง": ห้องเต็มจอ ซ่อนแถบซ้ายและรายการห้อง */
    html[data-dc-view="room"] .mx_MatrixChat > div > .mx_SpacePanel,
    html[data-dc-view="room"] .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        display: none !important;
    }
    html[data-dc-view="room"] .mx_MatrixChat > div > div:has(.mx_RoomView_wrapper) {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: none !important;
    }

    /* หัวห้อง: ปุ่มย้อนกลับ + ชื่อห้องไม่ล้น */
    .dc-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 40px;
        height: 40px;
        margin: 0 2px 0 -8px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: transparent;
        color: inherit;
        cursor: pointer;
    }
    .dc-back:active {
        background: rgba(127, 127, 127, 0.2);
    }
    .dc-back svg {
        width: 24px;
        height: 24px;
    }
    .mx_RoomHeader {
        padding-left: 12px !important;
        padding-right: 8px !important;
        gap: 8px !important;
    }
    .mx_RoomHeader_info,
    .mx_RoomHeader_heading {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* ไอคอนในหัวห้องบนจอเล็ก: เหลือที่จำเป็น (โทร / ข้อมูลห้อง) — ซ่อนปุ่มเธรดและรูปสมาชิกซ้อน */
    .mx_RoomHeader .mx_FacePile,
    .mx_RoomHeader [aria-label="เธรด"],
    .mx_RoomHeader [aria-label="Threads"] {
        display: none !important;
    }

    /* แผงข้อมูลห้อง / สมาชิก: เต็มจอ */
    .mx_RightPanel_ResizeWrapper {
        width: 100% !important;
        box-shadow: none;
    }

    /* ไทม์ไลน์: ลดขอบซ้ายขวา ให้ข้อความกว้างขึ้น */
    .mx_RoomView_MessageList {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    /* ช่องพิมพ์: ขอบมน ติดล่าง */
    .mx_MessageComposer {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* หน้าต่าง dialog: เกือบเต็มจอ */
    .mx_Dialog {
        max-width: calc(100vw - 16px) !important;
        max-height: calc(100dvh - 16px) !important;
        box-sizing: border-box;
        padding: 20px 16px !important;
        border-radius: 16px !important;
    }
    .mx_Dialog_fixedWidth {
        width: calc(100vw - 16px) !important;
    }

    /* การตั้งค่า: Element ย่อแท็บเป็นคอลัมน์ไอคอนแบบ position:fixed ซึ่งไปทับเนื้อหาบนจอแคบ
       → เปลี่ยนเป็นแถบแท็บเลื่อนแนวนอนด้านบน มีชื่อแท็บ */
    .mx_TabbedView {
        display: flex !important;
        flex-direction: column !important;
        position: static !important;
        height: auto !important;
        max-height: calc(100dvh - 120px);
    }
    .mx_TabbedView .mx_TabbedView_tabLabels {
        position: static !important;
        display: flex !important;
        flex-direction: row !important;
        flex: 0 0 auto;
        overflow-x: auto;
        overflow-y: hidden;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        height: auto !important;
        gap: 6px;
        margin: 0 0 12px !important;
        padding: 0 0 8px !important;
        scrollbar-width: none;
    }
    .mx_TabbedView .mx_TabbedView_tabLabel {
        flex: 0 0 auto;
        width: auto !important;
        padding: 8px 14px !important;
        border-radius: 999px !important;
        white-space: nowrap;
    }
    .mx_TabbedView .mx_TabbedView_tabLabel_text {
        display: inline !important;
    }
    .mx_TabbedView .mx_TabbedView_tabPanel {
        margin-left: 0 !important;
        padding: 0 !important;
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }

    /* หน้า login: การ์ดเต็มจอ */
    .mx_AuthPage {
        padding: 0 !important;
    }
    .mx_AuthPage_modal {
        width: 100% !important;
        min-height: 100dvh;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        flex-direction: column !important;
    }
    /* กรอบ "glass" ของ Element รอบการ์ด — บนมือถือเอาออก ให้เต็มจอจริง */
    .mx_AuthPage_modalContent > [class*="_glass_"] {
        padding: 0 !important;
        border-radius: 0 !important;
        background: none !important;
        border: 0 !important;
    }
    .mx_AuthPage_modalContent > [class*="_glass_"] > * {
        border-radius: 0 !important;
        min-height: 100dvh;
        box-sizing: border-box;
    }
    .mx_HomePage_body > div {
        padding: 20px 16px;
    }
    .mx_AuthHeader {
        width: 100% !important;
        padding: 32px 24px 8px !important;
        border: 0 !important;
    }
    .mx_AuthBody {
        width: 100% !important;
        box-sizing: border-box;
        padding: 16px 24px 32px !important;
        border-radius: 0 !important;
    }
}

/* =====================================================================
 * ธีม "หรู" — มรกตเข้ม + กระจกฝ้า + ทองอ่อน (ทับกฎด้านบน)
 * ===================================================================== */

:root,
[class*="cpd-theme"] {
    --dc-emerald: #2bb673;
    --dc-emerald-2: #1f8f5a;
    --dc-mint: #7be3b0;
    --dc-gold: #d9b26a;
    --dc-ink: #0b1014;
    --dc-glass: rgba(18, 25, 31, 0.72);
    --dc-hair: rgba(255, 255, 255, 0.08);
    --dc-grad: linear-gradient(135deg, #34c983 0%, #1f8f5a 100%);
}

/* ---------- พื้นหลังหน้า login / welcome ---------- */
.mx_AuthPage {
    background:
        radial-gradient(900px 520px at 12% -8%, rgba(52, 201, 131, 0.28), transparent 62%),
        radial-gradient(700px 480px at 108% 105%, rgba(217, 178, 106, 0.16), transparent 60%),
        radial-gradient(600px 400px at 85% 10%, rgba(31, 143, 90, 0.18), transparent 60%),
        linear-gradient(180deg, #0b1014 0%, #0e151a 100%) !important;
}
.mx_AuthPage_modalContent > [class*="_glass_"] {
    background: transparent !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 480px;
    margin: 0 auto;
    border: 0 !important;
}
.mx_AuthPage_modalContent > [class*="_glass_"] > * {
    width: 100% !important;
    box-sizing: border-box;
    background: var(--dc-glass) !important;
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--dc-hair) !important;
    border-radius: 24px !important;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.06) inset,
        0 30px 80px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(43, 182, 115, 0.06);
}
.mx_AuthPage_modal {
    background: transparent !important;
    box-shadow: none !important;
}

/* โลโก้: เรืองแสงเบา ๆ */
.mx_WelcomePage_body > div > img:first-child,
.mx_AuthHeaderLogo img {
    filter: drop-shadow(0 6px 22px rgba(43, 182, 115, 0.35));
}

/* หัวข้อ: ตัวหนา ไล่สีอ่อน */
.mx_WelcomePage_body > div > h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    background: linear-gradient(180deg, #ffffff 0%, #cfe9dc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ปุ่มหลัก */
.mx_WelcomePage_body a[href="#/login"],
.mx_HomePage_body > div > div > a[href^="#/"] {
    background: var(--dc-grad) !important;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.25) inset,
        0 10px 28px rgba(43, 182, 115, 0.35);
    letter-spacing: 0.01em;
}
.mx_WelcomePage_body a[href="#/login"]:hover,
.mx_HomePage_body > div > div > a[href^="#/"]:hover {
    filter: brightness(1.06);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.25) inset,
        0 14px 34px rgba(43, 182, 115, 0.45);
}
.mx_HomePage_body > div > div > a[href^="#/"] + a[href^="#/"] {
    background: transparent !important;
    color: var(--dc-mint) !important;
    box-shadow: 0 0 0 1px rgba(123, 227, 176, 0.45) inset;
}

/* รายการจุดเด่น: ไอคอนในกรอบสี */
.mx_WelcomePage_body > div > ul {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--dc-hair);
    padding: 10px 14px;
}
.mx_WelcomePage_body > div > ul > li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
}
.mx_WelcomePage_body li > img,
.mx_HomePage_body b > img {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 7px;
    box-sizing: border-box;
    border-radius: 10px;
    background: rgba(43, 182, 115, 0.12);
    box-shadow: 0 0 0 1px rgba(43, 182, 115, 0.22) inset;
}
.mx_HomePage_body b > img {
    background: rgba(224, 160, 48, 0.12);
    box-shadow: 0 0 0 1px rgba(224, 160, 48, 0.3) inset;
    vertical-align: middle;
    margin-right: 10px;
}
/* ลิงก์ดาวน์โหลดแอป */
.mx_WelcomePage_body a[href="/download"] {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--dc-mint) !important;
    text-decoration: none !important;
    font-weight: 600;
}
.mx_WelcomePage_body a[href="/download"] > img {
    width: 20px;
    height: 20px;
}

/* ---------- ฟอร์ม login ---------- */
.mx_AuthBody {
    background: transparent !important;
}
.mx_AuthBody h1,
.mx_AuthBody h2 {
    font-weight: 700;
    letter-spacing: -0.01em;
}
.mx_AuthBody .mx_Field {
    border-radius: 12px !important;
}
.mx_AuthBody .mx_Field input {
    min-height: 46px;
}
.mx_AuthBody .mx_Login_submit,
.mx_AuthBody button[type="submit"],
.mx_AuthBody input[type="submit"] {
    background: var(--dc-grad) !important;
    border: 0 !important;
    border-radius: 999px !important;
    min-height: 48px;
    box-shadow: 0 10px 28px rgba(43, 182, 115, 0.35);
}

/* ---------- หน้าแรกหลัง login ---------- */
.mx_HomePage_body > div > h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.mx_HomePage_body > div > h2 {
    color: var(--dc-mint);
    font-weight: 700;
    padding-top: 18px;
    border-top: 1px solid var(--dc-hair);
}
.mx_HomePage_body > div > div:has(> ul) {
    border: 1px solid rgba(224, 160, 48, 0.45);
    background: linear-gradient(180deg, rgba(224, 160, 48, 0.1), rgba(224, 160, 48, 0.04));
    border-radius: 18px;
    padding: 16px 20px;
}

/* ---------- ในแอป: รายการห้อง / หัวห้อง / ช่องพิมพ์ ---------- */
.mx_RoomListItemView {
    border-radius: 12px !important;
    transition: background 0.15s ease;
}
.mx_RoomListItemView[aria-selected="true"],
.mx_RoomListItemView[class*="_selected"] {
    background: linear-gradient(90deg, rgba(43, 182, 115, 0.2), rgba(43, 182, 115, 0.06)) !important;
    box-shadow: 0 0 0 1px rgba(43, 182, 115, 0.25) inset;
}
.mx_RoomHeader {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--dc-hair) !important;
}
.mx_MessageComposer_wrapper,
.mx_MessageComposer .mx_MessageComposer_row {
    border-radius: 999px;
}
.mx_MessageComposer .mx_BasicMessageComposer {
    border-radius: 22px;
}
.mx_MessageComposer {
    border-top: 1px solid var(--dc-hair);
}

/* ---------- มือถือ: การ์ด login เต็มจอ (ทับกฎ glass ด้านบน) ---------- */
@media (max-width: 767px) {
    .mx_AuthPage_modalContent > [class*="_glass_"] {
        max-width: none;
    }
    .mx_AuthPage_modalContent > [class*="_glass_"] > * {
        border-radius: 0 !important;
        border: 0 !important;
        min-height: 100dvh;
        padding: 40px 20px 24px !important;
        background: rgba(11, 16, 20, 0.55) !important;
        box-shadow: none;
    }
}

/* ---------- หน้า login (ไม่มี glass): การ์ดกระจกมืดแทนพื้นขาวเบลอของ Element ---------- */
.mx_AuthPage_modalBlur {
    display: none !important;
}
.mx_AuthPage_modalContent:not(:has(> [class*="_glass_"])) {
    background: var(--dc-glass) !important;
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--dc-hair);
    border-radius: 24px;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.06) inset,
        0 30px 80px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}
.mx_AuthPage_modalContent:has(> [class*="_glass_"]) {
    background: transparent !important;
}
.mx_AuthHeader {
    border-right: 1px solid var(--dc-hair) !important;
}
.mx_AuthBody,
.mx_AuthBody h1,
.mx_AuthBody h2 {
    color: #e6edf3 !important;
}
.mx_AuthBody .mx_Field {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.14) !important;
}
.mx_AuthBody .mx_Field:focus-within {
    border-color: var(--dc-emerald) !important;
    box-shadow: 0 0 0 3px rgba(43, 182, 115, 0.2);
}
.mx_AuthBody .mx_Field label {
    background: transparent !important;
}
.mx_AuthBody .mx_Field input {
    color: #e6edf3 !important;
}
@media (max-width: 767px) {
    .mx_AuthPage_modalContent:not(:has(> [class*="_glass_"])) {
        border-radius: 0;
        border: 0;
        min-height: 100dvh;
        background: rgba(11, 16, 20, 0.55) !important;
    }
    .mx_AuthHeader {
        border-right: 0 !important;
    }
}
@media (max-width: 767px) {
    /* login บนมือถือ: โลโก้ด้านบน ฟอร์มด้านล่าง (ไม่แบ่งซ้าย-ขวา) */
    .mx_AuthPage_modalContent {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .mx_AuthHeader {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        min-height: 0 !important;
        height: auto !important;
        padding: calc(24px + env(safe-area-inset-top)) 24px 0 !important;
        box-sizing: border-box;
    }
    .mx_AuthHeaderLogo {
        height: auto !important;
        width: auto !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .mx_AuthHeaderLogo img {
        width: 140px !important;
        height: auto !important;
    }
    .mx_AuthHeader .mx_LanguageDropdown {
        width: auto !important;
        margin: 0 !important;
    }
    .mx_AuthBody {
        padding: 28px 24px 32px !important;
    }
    .mx_AuthBody h1 {
        font-size: 26px !important;
        margin-top: 0 !important;
    }
}
@media (max-width: 767px) {
    /* หน้ายืนยันตัวตน / recovery key: การ์ดของ Element กว้างตายตัว 600px → ให้พอดีจอ */
    .mx_EncryptionCard,
    .mx_CompleteSecurity_body > * {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    .mx_EncryptionCard button,
    .mx_CompleteSecurity_body button {
        max-width: 100%;
        white-space: normal;
    }
}
@media (max-width: 767px) {
    /* การตั้งค่าบนมือถือ: ไอคอนแท็บไม่ชิดตัวหนังสือ และเนื้อหาไม่ล้นขอบ */
    .mx_TabbedView .mx_TabbedView_tabLabel {
        gap: 6px;
    }
    .mx_TabbedView .mx_TabbedView_tabLabel_icon,
    .mx_TabbedView .mx_TabbedView_tabLabel > svg {
        margin-right: 0 !important;
        flex: 0 0 auto;
    }
    .mx_Dialog,
    .mx_TabbedView .mx_TabbedView_tabPanel {
        overflow-x: hidden;
    }
    .mx_TabbedView .mx_TabbedView_tabPanel * {
        max-width: 100%;
        box-sizing: border-box;
    }
    .mx_SettingsTab,
    .mx_SettingsTab_sections,
    .mx_SettingsSection {
        padding-left: 0 !important;
        padding-right: 0 !important;
        min-width: 0 !important;
    }
}
@media (max-width: 767px) {
    .mx_Dialog .mx_Dialog_fixedWidth {
        width: auto !important;
        max-width: 100% !important;
    }
    .mx_TabbedView.mx_TabbedView_tabsOnLeft {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .mx_TabbedView.mx_TabbedView_tabsOnLeft .mx_TabbedView_tabPanel {
        margin-inline-start: 0 !important;
        padding-inline-start: 0 !important;
    }
}

/* แท็บเล็ต/คอม: รายการห้องไม่แคบจนชื่อห้องถูกตัด (Element จำความกว้างที่ลากไว้ — กันไม่ให้เล็กเกิน) */
@media (min-width: 768px) {
    .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        min-width: 240px !important;
    }
}
@media (min-width: 1200px) {
    .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        min-width: 280px !important;
    }
}
@media (min-width: 768px) and (max-width: 1199px) {
    .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        max-width: 280px !important;
    }
}
@media (min-width: 1200px) {
    .mx_MatrixChat > div > div:has(.mx_LeftPanel_outerWrapper) {
        max-width: 400px !important;
    }
}
@media (max-width: 767px) {
    /* toast (สายเรียกเข้า/แจ้งเตือน) อยู่มุมขวาบน → บังปุ่มในหัวห้องบนมือถือ: ย้ายลงใต้หัวห้อง เต็มความกว้าง */
    .mx_ToastContainer {
        top: calc(64px + env(safe-area-inset-top)) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none !important;
    }
    .mx_ToastContainer .mx_Toast_toast {
        width: auto !important;
        max-width: none !important;
        border-radius: 16px !important;
    }
}
@media (min-width: 768px) and (max-width: 1199px) {
    /* แท็บเล็ต: toast ลงมาใต้หัวห้อง ไม่บังปุ่มโทร/ข้อมูลห้อง */
    .mx_ToastContainer {
        top: 72px !important;
    }
}

/* toast อยู่บนสุดเสมอ — ไม่ถูกหน้าจอโทร (iframe) ตัดขอบ */
.mx_ToastContainer {
    z-index: 4000 !important;
}
.mx_ToastContainer .mx_Toast_toast {
    max-width: calc(100vw - 16px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45) !important;
}

/* แท็บเล็ต 768–1024: Element ย่อแท็บการตั้งค่าเหลือไอคอน (position:fixed) → ใช้แถบแท็บแนวนอนแบบมือถือ มีชื่อแท็บ */
@media (min-width: 768px) and (max-width: 1024px) {
    .mx_TabbedView {
        display: flex !important;
        flex-direction: column !important;
        position: static !important;
        height: auto !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .mx_TabbedView .mx_TabbedView_tabLabels {
        position: static !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap;
        flex: 0 0 auto;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        height: auto !important;
        gap: 6px;
        margin: 0 0 16px !important;
        padding: 0 0 8px !important;
    }
    .mx_TabbedView .mx_TabbedView_tabLabel {
        flex: 0 0 auto;
        width: auto !important;
        padding: 8px 14px !important;
        border-radius: 999px !important;
        white-space: nowrap;
        gap: 6px;
    }
    .mx_TabbedView .mx_TabbedView_tabLabel_text {
        display: inline !important;
    }
    .mx_TabbedView .mx_TabbedView_tabPanel {
        margin-inline-start: 0 !important;
        padding-inline-start: 0 !important;
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }
}

@media (max-width: 767px) {
    /* มือถือไม่มี hover — tooltip ของแท็บค้างทับชื่อแท็บถัดไป */
    .mx_TabbedView ~ [role="tooltip"],
    body > [data-radix-popper-content-wrapper]:has([role="tooltip"]),
    [role="tooltip"] {
        display: none !important;
    }
    /* ตั้งค่าห้อง: รูปห้องอยู่ด้านบน ฟอร์มเต็มความกว้าง (เดิมวางข้างกันแล้วรูปถูกตัด) */
    .mx_RoomProfileSettings_profile {
        flex-direction: column-reverse !important;
        align-items: flex-start !important;
        gap: 12px;
    }
    .mx_RoomProfileSettings_profile .mx_RoomProfileSettings_profile_controls {
        width: 100%;
        margin-inline-end: 0 !important;
    }
}
@media (max-width: 1024px) and (pointer: coarse), (min-width: 768px) and (max-width: 1024px) {
    /* แท็บเล็ต (จอสัมผัส): tooltip ค้างหลังแตะ ทับชื่อแท็บ */
    .mx_Dialog ~ [role="tooltip"],
    [data-radix-popper-content-wrapper]:has([role="tooltip"]) {
        display: none !important;
    }
}
@media (min-width: 768px) {
    /* toast อยู่ในคอลัมน์รายการห้อง (ถูกจำกัดความกว้าง) → ลอยอิสระ ไม่ถูกตัดขอบ */
    .mx_ToastContainer {
        position: fixed !important;
        left: 76px !important;
        right: auto !important;
        width: 360px !important;
        max-width: calc(100vw - 92px) !important;
    }
}

/* ใช้ง่าย: ไม่ต้อง "ยืนยัน" เพื่อน — แค่ส่งคำขอแชทแล้วอีกฝ่ายกดรับ
   ซ่อนปุ่ม/ส่วนชวนยืนยันผู้ใช้ในแผงโปรไฟล์ (แชทยังเข้ารหัสเหมือนเดิม;
   ถ้าตัวตนของใครเปลี่ยน Element ยังเตือนในห้องตามปกติ) */
.mx_UserInfo_verification,
.mx_UserInfo_container_verifyButton,
.mx_UserInfo_verify_button,
.mx_UserInfo_startVerification {
    display: none !important;
}

/* ปุ่มที่ 3 ในหน้าแรก: "โหลดแอปมือถือ" (ลิงก์ /download ไม่ขึ้นต้นด้วย #/) */
.mx_HomePage_body > div > div > a[href="/download"] {
    display: inline-block;
    margin: 8px 8px 4px 0;
    padding: 10px 20px;
    border-radius: 999px;
    color: var(--dc-mint) !important;
    text-decoration: none !important;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(123, 227, 176, 0.45) inset;
}
