/**
 * MYPX Embed Card — สไตล์การ์ดที่ผู้เขียนแทรกผ่าน Jodit
 * ใช้ทั้งใน editor (WYSIWYG) และหน้าเว็บจริง (post / page / section)
 * อย่าใส่ style inline ใน HTML ของการ์ด เพื่อให้ปรับธีมได้จากไฟล์นี้ไฟล์เดียว
 */
.mypx-embed-card {
    --mypx-card-radius: 14px;
    --mypx-card-shadow: 0 4px 18px rgba(15, 23, 42, .08);
    --mypx-card-shadow-hover: 0 10px 30px rgba(15, 23, 42, .14);
    --mypx-card-border: #e5e7eb;
    --mypx-card-bg: #ffffff;
    --mypx-card-fg: #0f172a;
    --mypx-card-muted: #475569;
    --mypx-card-accent: #2563eb;

    display: block;
    margin: 1.5rem 0;
    border: 1px solid var(--mypx-card-border);
    border-radius: var(--mypx-card-radius);
    background: var(--mypx-card-bg);
    box-shadow: var(--mypx-card-shadow);
    overflow: hidden;
    transition: box-shadow .2s ease, transform .2s ease;
}
.mypx-embed-card:hover {
    box-shadow: var(--mypx-card-shadow-hover);
}
.mypx-embed-card-inner {
    display: block;
    color: inherit;
    text-decoration: none;
}
a.mypx-embed-card-inner,
a.mypx-embed-card-inner:hover,
a.mypx-embed-card-inner:focus {
    color: inherit;
    text-decoration: none;
}
.mypx-embed-card-media {
    display: block;
    margin: 0;
    overflow: hidden;
    position: relative;
    isolation: isolate;
    background: #141414;
    aspect-ratio: 1 / 1;                /* แนวตั้ง (stacked) = 1:1 */
}
.mypx-embed-card-media img {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;                 /* เห็นรูปครบ ไม่ crop; ช่องว่างจะถูก bg เบลอเติมให้ */
    object-position: center;
    transition: transform .35s ease;
    /* แยกสไตล์ออกจาก theme content (เช่น .single-news-content img { margin:1em 0; border-radius:8px })
       การ์ดคุม aspect-ratio / border-radius / spacing ของตัวเองอยู่แล้ว */
    margin: 0;
    border-radius: 0;
}
/* กันรูปใน body ของการ์ด (จาก Jodit) โดน margin 1em ของ .single-news-content img ดันห่างเกิน
   ให้ใช้ระยะที่พอเหมาะในกรอบการ์ดแทน */
.mypx-embed-card .mypx-embed-card-text img {
    margin: .35em 0;
    max-width: 100%;
    height: auto;
}
/* พื้นหลังเบลอ (เติมโดย card-embed.js จากรูปเดียวกัน) */
.mypx-embed-card-media .mypxc-bg {
    position: absolute;
    inset: -10%;
    background-color: white;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(18px) brightness(1.9) saturate(.6);
    transform: scale(1.15);
    pointer-events: none;
    z-index: 0;
}
/* placeholder SVG (ไม่มีรูป) — ยกเลิก bg ดำ + ใช้ contain */
.mypx-embed-card-media img[src^="data:image/svg"] {
    background: #f1f5f9;
    padding: 8px;
}
.mypx-embed-card:hover .mypx-embed-card-media img {
    transform: scale(1.02);
}
.mypx-embed-card-body {
    padding: 1rem 1.15rem 1.15rem;
    color: var(--mypx-card-fg);
}
.mypx-embed-card-title {
    display: block;
    margin: 0 0 .4rem;
    font-size: 1.18rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--mypx-card-fg);
}
.mypx-embed-card-text {
    font-size: .98rem;
    color: var(--mypx-card-muted);
    line-height: 1.65;
}
.mypx-embed-card-text > *:first-child { margin-top: 0; }
.mypx-embed-card-text > *:last-child { margin-bottom: 0; }
.mypx-embed-card-text p { margin: 0 0 .55rem; }
.mypx-embed-card-text ul,
.mypx-embed-card-text ol { margin: 0 0 .55rem 1.25rem; padding: 0; }
.mypx-embed-card-cta {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin-top: .85rem;
    font-weight: 600;
    color: var(--mypx-card-accent);
}
.mypx-embed-card-cta::after {
    content: "→";
    transition: transform .2s ease;
}
a.mypx-embed-card-inner:hover .mypx-embed-card-cta { text-decoration: underline; }
a.mypx-embed-card-inner:hover .mypx-embed-card-cta::after { transform: translateX(3px); }

/* ── Variant: ไม่มีรูป ─────────────────────────────────────────── */
.mypx-embed-card.is-no-image .mypx-embed-card-media { display: none; }

/* ── Variant: รูปซ้าย (horizontal) — responsive ──────────────── */
@media (min-width: 576px) {
    .mypx-embed-card.is-inline {
        display: grid;
        grid-template-columns: minmax(200px, 260px) 1fr;
        gap: 0;
        align-items: stretch;
    }
    .mypx-embed-card.is-inline .mypx-embed-card-inner {
        display: contents;
    }
    .mypx-embed-card.is-inline .mypx-embed-card-media {
        aspect-ratio: 4 / 5;             /* แนวนอน (inline) รูปซ้าย = 4:5 */
        height: auto;
        min-height: 0;
    }
    .mypx-embed-card.is-inline .mypx-embed-card-body {
        align-self: center;
    }
}

/* ── ความกว้าง (12-column grid) — จัดกึ่งกลางในคอนเทนเนอร์เนื้อหา ─ */
.mypx-embed-card[data-w]      { margin-left: auto; margin-right: auto; }
@media (min-width: 576px) {
    .mypx-embed-card[data-w="1"]  { max-width:  8.3333%; }
    .mypx-embed-card[data-w="2"]  { max-width: 16.6666%; }
    .mypx-embed-card[data-w="3"]  { max-width: 25%; }
    .mypx-embed-card[data-w="4"]  { max-width: 33.3333%; }
    .mypx-embed-card[data-w="5"]  { max-width: 41.6666%; }
    .mypx-embed-card[data-w="6"]  { max-width: 50%; }
    .mypx-embed-card[data-w="7"]  { max-width: 58.3333%; }
    .mypx-embed-card[data-w="8"]  { max-width: 66.6666%; }
    .mypx-embed-card[data-w="9"]  { max-width: 75%; }
    .mypx-embed-card[data-w="10"] { max-width: 83.3333%; }
    .mypx-embed-card[data-w="11"] { max-width: 91.6666%; }
    .mypx-embed-card[data-w="12"] { max-width: 100%; }
}
@media (max-width: 575.98px) {
    /* จอเล็ก — การ์ดที่แคบกว่าครึ่งจะยุบเต็มความกว้างเพื่ออ่านง่าย */
    .mypx-embed-card[data-w="1"],
    .mypx-embed-card[data-w="2"],
    .mypx-embed-card[data-w="3"],
    .mypx-embed-card[data-w="4"],
    .mypx-embed-card[data-w="5"] {
        max-width: 100%;
    }
    .mypx-embed-card[data-w="6"]  { max-width: 90%; }
    .mypx-embed-card[data-w="7"]  { max-width: 92%; }
    .mypx-embed-card[data-w="8"]  { max-width: 95%; }
    .mypx-embed-card[data-w="9"],
    .mypx-embed-card[data-w="10"],
    .mypx-embed-card[data-w="11"],
    .mypx-embed-card[data-w="12"] { max-width: 100%; }
}

/* ── ความสูงแบบกำหนดเอง (fixed height) ────────────────────────── */
.mypx-embed-card.has-fixed-height {
    height: var(--mypx-card-h, auto);
    display: flex;
    flex-direction: column;
}
.mypx-embed-card.has-fixed-height .mypx-embed-card-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
}
.mypx-embed-card.has-fixed-height .mypx-embed-card-media {
    aspect-ratio: unset;
    flex: 1 1 0;
    height: auto;
    min-height: 0;
}
.mypx-embed-card.has-fixed-height .mypx-embed-card-body {
    flex: 0 0 auto;
    overflow: auto;
    max-height: 65%;
}
/* fixed height + inline: ลบ grid ของ is-inline แล้วใช้ flex แทน */
@media (min-width: 576px) {
    .mypx-embed-card.has-fixed-height.is-inline {
        display: flex;
        flex-direction: row;
        grid-template-columns: none;
    }
    .mypx-embed-card.has-fixed-height.is-inline .mypx-embed-card-inner {
        display: flex;
        flex-direction: row;
        height: 100%;
        width: 100%;
    }
    .mypx-embed-card.has-fixed-height.is-inline .mypx-embed-card-media {
        flex: 0 0 40%;
        height: 100%;
        min-height: 0;
    }
    .mypx-embed-card.has-fixed-height.is-inline .mypx-embed-card-body {
        flex: 1 1 0;
        min-height: 0;
        max-height: 100%;
        overflow: auto;
    }
}
/* การ์ดสูงคงที่ + ไม่มีรูป — ให้ body ขยายเต็ม */
.mypx-embed-card.has-fixed-height.is-no-image .mypx-embed-card-body {
    flex: 1 1 auto;
    max-height: 100%;
}

/* ── Variant: คลิกภาพเพื่อขยายเต็มจอ (frontend) ────────────────
   ในเอดิเตอร์ปล่อยให้ cursor ของ Jodit (pointer) ทำงานตามปกติ */
.mypx-embed-card.is-image-zoom .mypx-embed-card-media,
.mypx-embed-card.is-image-zoom .mypx-embed-card-media img {
    cursor: zoom-in;
}
.mypx-embed-card.is-image-zoom .mypx-embed-card-media:focus-visible {
    outline: 2px solid var(--mypx-card-accent, #2563eb);
    outline-offset: 2px;
}
.mypx-embed-card.is-image-zoom .mypx-embed-card-media img {
    transition: transform .35s ease, filter .18s ease;
}
.mypx-embed-card.is-image-zoom .mypx-embed-card-media:hover img {
    filter: brightness(.92);
}
.jodit-wysiwyg .mypx-embed-card.is-image-zoom .mypx-embed-card-media,
.jodit-wysiwyg .mypx-embed-card.is-image-zoom .mypx-embed-card-media img {
    cursor: pointer;                        /* ในเอดิเตอร์ ใช้ cursor ปกติ — ดับเบิลคลิกเพื่อแก้ไข */
}

/* ── ตัวช่วยในโหมด editor (Jodit) ────────────────────────────── */
.jodit-wysiwyg .mypx-embed-card {
    cursor: pointer;
    position: relative;
    outline: 2px dashed transparent;
    outline-offset: 2px;
}
.jodit-wysiwyg .mypx-embed-card:hover {
    outline-color: rgba(37, 99, 235, .55);
}
.jodit-wysiwyg .mypx-embed-card.is-selected {
    outline-color: #2563eb;
    outline-style: solid;
}
.jodit-wysiwyg .mypx-embed-card::after {
    content: "ดับเบิลคลิกเพื่อแก้ไข";
    position: absolute;
    top: 6px;
    right: 8px;
    background: rgba(37, 99, 235, .92);
    color: #fff;
    font-size: .72rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    opacity: 0;
    transition: opacity .15s ease;
    pointer-events: none;
}
.jodit-wysiwyg .mypx-embed-card:hover::after,
.jodit-wysiwyg .mypx-embed-card.is-selected::after {
    opacity: 1;
}

/* ─────────────────────────────────────────────────────────────
 * Card Grid — วางการ์ดเป็นคอลัมน์ (จัดแถว)
 *   <div class="mypx-card-grid" data-mypx-card-grid="v1"
 *        data-cols="3" data-gap="md">
 *       <div class="mypx-embed-card">...</div>
 *       <div class="mypx-embed-card">...</div>
 *   </div>
 * ───────────────────────────────────────────────────────────── */
.mypx-card-grid {
    display: grid;
    gap: var(--mypxg-gap, 1rem);
    grid-template-columns: repeat(var(--mypxg-cols, 3), minmax(0, 1fr));
    margin: 1.5rem 0;
    align-items: stretch;
}
.mypx-card-grid[data-gap="sm"] { --mypxg-gap: .5rem;  }
.mypx-card-grid[data-gap="md"] { --mypxg-gap: 1rem;   }
.mypx-card-grid[data-gap="lg"] { --mypxg-gap: 1.5rem; }
.mypx-card-grid[data-gap="xl"] { --mypxg-gap: 2rem;   }
.mypx-card-grid[data-cols="1"] { --mypxg-cols: 1; }
.mypx-card-grid[data-cols="2"] { --mypxg-cols: 2; }
.mypx-card-grid[data-cols="3"] { --mypxg-cols: 3; }
.mypx-card-grid[data-cols="4"] { --mypxg-cols: 4; }
.mypx-card-grid[data-cols="5"] { --mypxg-cols: 5; }
.mypx-card-grid[data-cols="6"] { --mypxg-cols: 6; }

/* Responsive ลดคอลัมน์ลงอัตโนมัติบนจอเล็ก */
@media (max-width: 991.98px) {
    .mypx-card-grid[data-cols="3"],
    .mypx-card-grid[data-cols="4"],
    .mypx-card-grid[data-cols="5"],
    .mypx-card-grid[data-cols="6"] { --mypxg-cols: 2; }
}
@media (max-width: 575.98px) {
    .mypx-card-grid,
    .mypx-card-grid[data-cols]    { --mypxg-cols: 1; }
}

/* การ์ดภายใน grid — จัดเป็น stacked, ไม่ใช้ max-width ของ data-w และสูงเท่ากันทั้งแถว */
.mypx-card-grid > .mypx-embed-card {
    margin: 0 !important;
    max-width: none !important;
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    height: 100%;
}
.mypx-card-grid > .mypx-embed-card > .mypx-embed-card-inner,
.mypx-card-grid > .mypx-embed-card.is-inline > .mypx-embed-card-inner {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}
.mypx-card-grid > .mypx-embed-card .mypx-embed-card-media {
    aspect-ratio: 1 / 1 !important;
    height: auto !important;
    min-height: 0 !important;
    flex: 0 0 auto !important;
    padding: 2rem;
}
.mypx-card-grid > .mypx-embed-card .mypx-embed-card-body {
    flex: 1 1 auto;
    max-height: none !important;
    overflow: visible !important;
}

/* ตัวช่วยในโหมด editor — เห็นขอบกริดและมี hint ให้คลิก */
.jodit-wysiwyg .mypx-card-grid {
    position: relative;
    outline: 2px dashed transparent;
    outline-offset: 4px;
    border-radius: 8px;
    transition: outline-color .15s ease;
}
.jodit-wysiwyg .mypx-card-grid:hover {
    outline-color: rgba(14, 165, 233, .55);
}
.jodit-wysiwyg .mypx-card-grid.is-grid-selected {
    outline-style: solid;
    outline-color: #0ea5e9;
}
.jodit-wysiwyg .mypx-card-grid::before {
    content: "กริดการ์ด • ดับเบิลคลิกการ์ดเพื่อแก้ไข / ดับเบิลคลิกพื้นที่ว่างเพื่อตั้งค่ากริด";
    position: absolute;
    top: -10px;
    left: 10px;
    transform: translateY(-100%);
    background: #0ea5e9;
    color: #fff;
    font-size: .72rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    opacity: 0;
    transition: opacity .15s ease;
    pointer-events: none;
    white-space: nowrap;
    font-family: system-ui, -apple-system, "Noto Sans Thai", sans-serif;
}
.jodit-wysiwyg .mypx-card-grid:hover::before,
.jodit-wysiwyg .mypx-card-grid.is-grid-selected::before {
    opacity: 1;
}

/* ── Placeholder card (สลอตว่างภายในกริดใหม่) ─────────────────── */
.mypx-embed-card.is-placeholder {
    background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 10px, #eef2f7 10px, #eef2f7 20px);
    border-style: dashed;
    min-height: 200px;
}
.mypx-embed-card.is-placeholder .mypx-embed-card-title {
    color: #475569;
}
.mypx-embed-card.is-placeholder .mypx-embed-card-text {
    color: #64748b;
}

/* ── Dark mode (Bootstrap 5 data-bs-theme) ───────────────────── */
[data-bs-theme="dark"] .mypx-embed-card {
    --mypx-card-border: #334155;
    --mypx-card-bg: #0f172a;
    --mypx-card-fg: #f1f5f9;
    --mypx-card-muted: #cbd5e1;
    --mypx-card-accent: #60a5fa;
    --mypx-card-shadow: 0 4px 18px rgba(0, 0, 0, .35);
    --mypx-card-shadow-hover: 0 10px 30px rgba(0, 0, 0, .45);
}
[data-bs-theme="dark"] .mypx-embed-card.is-placeholder {
    background: repeating-linear-gradient(45deg, #111827, #111827 10px, #1f2937 10px, #1f2937 20px);
}
[data-bs-theme="dark"] .mypx-embed-card.is-placeholder .mypx-embed-card-title {
    color: #cbd5e1;
}
[data-bs-theme="dark"] .mypx-embed-card.is-placeholder .mypx-embed-card-text {
    color: #94a3b8;
}
