/* ===========================================================================
 * mes789-system / assets/css/blocks.css
 * หน้าตาของบล็อกทั้ง 6 ชนิด + ตัวแก้ไขหน้า
 * โหลดเฉพาะหน้าที่ใช้ (site-page.php และ page-editor.php)
 * =========================================================================== */

/* ===========================================================================
   หน้าเว็บที่สร้างจากบล็อก
   =========================================================================== */
.site-page { padding: 8px 0 40px; }
.site-page-title {
    font-size: 1.9rem;
    color: var(--gold);
    margin: 0 0 6px;
    line-height: 1.35;
}
.site-page-meta {
    font-size: .8rem;
    color: var(--text-mute);
    margin: 0 0 26px;
}
/* เนื้อหายาว ๆ ต้องคุมความกว้างบรรทัด ไม่งั้นตาหลงบรรทัดตอนขึ้นบรรทัดใหม่ */
.site-page-body { max-width: 62ch; }

/* ---------- บล็อกทั่วไป ---------- */
.blk { margin: 0 0 20px; }
.blk:last-child { margin-bottom: 0; }
.a-left   { text-align: left; }
.a-center { text-align: center; }
.a-right  { text-align: right; }

/* ---------- 1. ข้อความ ---------- */
.blk-text h2, .blk-text h3, .blk-text h4 {
    color: var(--gold-soft);
    margin: 0 0 10px;
    line-height: 1.4;
}
.blk-text h2 { font-size: 1.35rem; }
.blk-text h3 { font-size: 1.15rem; }
.blk-text h4 { font-size: 1rem; }
.blk-body { line-height: 1.85; color: var(--text); }
.blk-body a { color: var(--gold-soft); text-decoration: underline; text-underline-offset: 2px; }
.blk-body ul, .blk-body ol { padding-left: 1.4em; margin: 10px 0; }
.blk-body li { margin-bottom: 6px; }

/* ---------- 2. รูปภาพ ---------- */
.blk-image { margin: 24px 0; }
.blk-image img { width: 100%; height: auto; display: block; border-radius: var(--radius-sm, 9px); }
.blk-image.w-wide   { max-width: 100%; }
.blk-image.w-narrow { max-width: 60%; margin-left: auto; margin-right: auto; }
.blk-image figcaption {
    font-size: .8rem;
    color: var(--text-mute);
    text-align: center;
    margin-top: 8px;
}

/* ---------- 3. ปุ่ม ---------- */
.blk-btn {
    display: inline-block;
    padding: .62rem 1.4rem;
    border-radius: 9px;
    font-weight: 600;
    font-size: .92rem;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.5;
}
.blk-btn.s-gold {
    background: var(--gold);
    color: #241a08;
    border-color: var(--gold);
}
.blk-btn.s-gold:hover { filter: brightness(1.1); }
.blk-btn.s-outline {
    background: transparent;
    color: var(--gold-soft);
    border-color: var(--gold-dim);
}
.blk-btn.s-outline:hover { border-color: var(--gold); color: var(--gold); }
.blk-btn.s-red {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}
.blk-btn.s-red:hover { filter: brightness(1.12); }

/* ---------- 4. เส้นคั่น ---------- */
.blk-divider hr { border: 0; border-top: 1px solid var(--line); margin: 0; }
.blk-divider.dots hr { border-top: 2px dotted var(--line); }
.blk-space { margin: 0; }

/* ---------- 5. คอลัมน์ ---------- */
.blk-columns { display: grid; gap: 20px; }
.blk-columns.n-2 { grid-template-columns: 1fr 1fr; }
.blk-columns.n-3 { grid-template-columns: repeat(3, 1fr); }
/* บนมือถือยุบเป็นแถวเดียวเสมอ — 2-3 ช่องบนจอแคบอ่านไม่ไหว */
@media (max-width: 640px) {
    .blk-columns.n-2, .blk-columns.n-3 { grid-template-columns: 1fr; }
}

/* ---------- 6. กล่องเน้น ---------- */
.blk-callout {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid;
    line-height: 1.75;
    font-size: .92rem;
}
.blk-callout-icon { font-size: 1.2rem; line-height: 1.5; flex-shrink: 0; }
.blk-callout-body strong { display: block; margin-bottom: 4px; }
.blk-callout.t-info  { background: rgba(70,120,160,.1); border-color: rgba(90,150,200,.3); color: #b8d4e8; }
.blk-callout.t-warn  { background: rgba(180,120,20,.12); border-color: rgba(212,175,55,.35); color: var(--gold-soft); }
.blk-callout.t-gold  { background: rgba(212,175,55,.1); border-color: var(--gold-dim); color: var(--gold-soft); }
.blk-callout.t-quote {
    background: transparent;
    border: 0;
    border-left: 3px solid var(--gold-dim);
    border-radius: 0;
    font-style: italic;
    color: var(--text-dim);
}

/* ===========================================================================
   ตัวแก้ไขหน้า (หลังบ้าน)
   =========================================================================== */
.pe-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.pe-item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 14px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.pe-item:last-child { border-bottom: 0; }
.pe-item-title { font-size: .95rem; color: var(--text); }
.pe-item-meta { font-size: .76rem; color: var(--text-mute); font-family: monospace; margin-top: 2px; }
.pe-empty { color: #b8860b; margin-left: 10px; font-family: inherit; }
.pe-item-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.pe-badge { font-size: .7rem; padding: 2px 9px; border-radius: 999px; border: 1px solid; }
.pe-badge.ok { color: #4a8f5e; border-color: #4a8f5e; }
.pe-badge.draft { color: var(--text-mute); border-color: var(--line); }

.pe-settings {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px; padding: 16px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius);
}
.pe-settings label { display: flex; flex-direction: column; gap: 5px; font-size: .84rem; color: var(--text-dim); }
.pe-settings input[type=text], .pe-settings input[type=number], .pe-settings select {
    padding: .5rem .7rem; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 7px; color: var(--text); font-family: inherit; font-size: .9rem;
}
.pe-settings small { font-size: .72rem; color: var(--text-mute); }
.pe-check { flex-direction: row !important; align-items: center; gap: 8px !important; }

.pe-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.pe-add {
    padding: .5rem .9rem; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 8px; color: var(--text-dim); cursor: pointer; font-family: inherit; font-size: .86rem;
}
.pe-add:hover { border-color: var(--gold-dim); color: var(--gold-soft); }

.pe-canvas { display: flex; flex-direction: column; gap: 12px; }
.pe-empty-state {
    padding: 40px 20px; text-align: center; color: var(--text-mute);
    border: 2px dashed var(--line); border-radius: var(--radius); font-size: .9rem;
}
.pe-block { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pe-block-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.pe-block-name { font-size: .84rem; color: var(--gold-soft); font-weight: 600; }
.pe-block-tools { display: flex; gap: 4px; }
.pe-block-tools button, .pe-x, .pe-mini {
    background: none; border: 1px solid var(--line); border-radius: 6px;
    color: var(--text-dim); cursor: pointer; font-family: inherit;
    width: 28px; height: 26px; line-height: 1; font-size: .85rem;
}
.pe-mini { width: auto; padding: 0 12px; height: 28px; margin-top: 8px; font-size: .8rem; }
.pe-block-tools button:hover:not(:disabled), .pe-mini:hover { border-color: var(--gold-dim); color: var(--gold-soft); }
.pe-block-tools button:disabled { opacity: .3; cursor: not-allowed; }
.pe-x:hover { border-color: var(--red-soft); color: var(--red-soft); }

.pe-field { display: flex; flex-direction: column; gap: 5px; padding: 10px 12px 0; }
.pe-field:last-child { padding-bottom: 12px; }
.pe-field span { font-size: .78rem; color: var(--text-mute); }
.pe-field input, .pe-field textarea, .pe-field select {
    padding: .5rem .7rem; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 7px; color: var(--text); font-family: inherit; font-size: .9rem;
    width: 100%; box-sizing: border-box;
}
.pe-field textarea { resize: vertical; line-height: 1.7; }
.pe-field input[type=range] { padding: 0; accent-color: var(--gold); }

.pe-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; padding: 12px; }
.pe-col { border: 1px dashed var(--line); border-radius: 8px; padding: 8px; }
.pe-col-head { font-size: .74rem; color: var(--text-mute); margin-bottom: 6px; }
.pe-inner { border: 1px solid var(--line); border-radius: 7px; margin-bottom: 8px; background: var(--bg-soft, #141010); }
.pe-inner-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 9px; font-size: .76rem; color: var(--text-dim); border-bottom: 1px solid var(--line);
}
.pe-col-add { display: flex; flex-wrap: wrap; gap: 5px; }
.pe-col-add button {
    font-size: .74rem; padding: 4px 9px; background: none; border: 1px solid var(--line);
    border-radius: 6px; color: var(--text-mute); cursor: pointer; font-family: inherit;
}
.pe-col-add button:hover { border-color: var(--gold-dim); color: var(--gold-soft); }

.pe-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; flex-wrap: wrap; }

/* ==========================================================================
   [ข้อ 2] บล็อกใหม่ 8 ตัว — ใช้ CSS ล้วน ไม่พึ่ง JS
   ========================================================================== */

/* 7. Hero — แบนเนอร์ใหญ่ */
.blk-hero {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  border-radius: var(--radius, 14px);
  overflow: hidden;
  margin: 18px 0;
  text-align: center;
}
.blk-hero::before {
  content: "";
  position: absolute;
  inset: 0;
}
.blk-hero.ov-dark::before  { background: rgba(0, 0, 0, .5); }
.blk-hero.ov-light::before { background: rgba(255, 255, 255, .25); }
.blk-hero.ov-none::before  { background: transparent; }
.blk-hero-inner {
  position: relative;
  z-index: 1;
  padding: 32px 24px;
  max-width: 640px;
}
.blk-hero-title { font-size: 30px; color: #fff; margin: 0 0 10px; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.blk-hero-sub { font-size: 17px; color: rgba(255,255,255,.9); margin: 0 0 16px; }

/* 8. Video — YouTube 16:9 */
.blk-video { margin: 18px 0; }
.blk-video-frame {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  border-radius: var(--radius, 14px);
  overflow: hidden;
  background: #000;
}
.blk-video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.blk-video-caption { text-align: center; color: var(--text-dim, #a1938c); font-size: 14px; margin-top: 8px; }

/* 9. Gallery — กริดรูป */
.blk-gallery { display: grid; gap: 8px; margin: 18px 0; }
.blk-gallery.g-2 { grid-template-columns: repeat(2, 1fr); }
.blk-gallery.g-3 { grid-template-columns: repeat(3, 1fr); }
.blk-gallery.g-4 { grid-template-columns: repeat(4, 1fr); }
.blk-gallery-item { margin: 0; aspect-ratio: 1; overflow: hidden; border-radius: 8px; }
.blk-gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 10. Timeline — ลำดับเหตุการณ์แนวตั้ง */
.blk-timeline { position: relative; margin: 18px 0; padding-left: 28px; }
.blk-timeline::before {
  content: "";
  position: absolute;
  left: 7px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--line, #2e2323);
}
.blk-tl-item { position: relative; padding-bottom: 22px; }
.blk-tl-dot {
  position: absolute;
  left: -28px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--gold, #d4af37);
  border: 3px solid var(--bg, #0c0a0a);
}
.blk-tl-label { display: inline-block; font-size: 13px; color: var(--gold, #d4af37); margin-bottom: 2px; }
.blk-tl-title { display: block; color: var(--text, #ece5e0); margin-bottom: 4px; }
.blk-tl-body { color: var(--text-dim, #a1938c); font-size: 15px; }

/* 11. Stats — การ์ดตัวเลข */
.blk-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 18px 0;
}
.blk-stat {
  flex: 1;
  min-width: 120px;
  text-align: center;
  background: var(--surface, #1a1414);
  border: 1px solid var(--line, #2e2323);
  border-radius: var(--radius-sm, 9px);
  padding: 18px 12px;
}
.blk-stat-value { display: block; font-size: 30px; font-weight: 700; color: var(--gold-soft, #f0d98a); }
.blk-stat-label { display: block; font-size: 13px; color: var(--text-dim, #a1938c); margin-top: 4px; }

/* 12. Flipbox — การ์ดพลิก (hover / focus) */
.blk-flipbox {
  margin: 18px 0;
  perspective: 1000px;
  max-width: 320px;
}
.blk-flip-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  transition: transform .6s;
  transform-style: preserve-3d;
}
.blk-flipbox:hover .blk-flip-inner,
.blk-flipbox:focus-within .blk-flip-inner { transform: rotateY(180deg); }
.blk-flip-front, .blk-flip-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius, 14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  background-size: cover;
  background-position: center;
}
.blk-flip-front { background: var(--surface-2, #221a1a); color: var(--text, #ece5e0); }
.blk-flip-back {
  background: var(--gold-dim, #8a7128);
  color: #fff;
  transform: rotateY(180deg);
}

/* 13. Accordion — พับเปิด/ปิด */
.blk-accordion { margin: 18px 0; }
.blk-acc-item {
  border: 1px solid var(--line, #2e2323);
  border-radius: var(--radius-sm, 9px);
  margin-bottom: 8px;
  background: var(--surface, #1a1414);
  overflow: hidden;
}
.blk-acc-item summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  color: var(--text, #ece5e0);
  user-select: none;
  list-style: none;
}
.blk-acc-item summary::-webkit-details-marker { display: none; }
.blk-acc-item summary::after { content: "＋"; float: right; color: var(--gold, #d4af37); }
.blk-acc-item[open] summary::after { content: "－"; }
.blk-acc-body { padding: 0 16px 14px; color: var(--text-dim, #a1938c); }

/* 14. Quotecard — การ์ดคำคม */
.blk-quotecard {
  margin: 18px 0;
  padding: 24px 28px;
  background: var(--surface, #1a1414);
  border-left: 4px solid var(--gold, #d4af37);
  border-radius: 0 var(--radius, 14px) var(--radius, 14px) 0;
}
.blk-quotecard blockquote {
  margin: 0;
  font-size: 20px;
  line-height: 1.6;
  color: var(--text, #ece5e0);
  font-style: italic;
}
.blk-quotecard figcaption {
  margin-top: 12px;
  color: var(--gold-soft, #f0d98a);
  font-size: 15px;
}

/* มือถือ — แกลเลอรี/สถิติปรับคอลัมน์ */
@media (max-width: 600px) {
  .blk-gallery.g-3, .blk-gallery.g-4 { grid-template-columns: repeat(2, 1fr); }
  .blk-hero-title { font-size: 24px; }
  .blk-stat { min-width: calc(50% - 6px); }
}

/* ===========================================================================
   🎠 สไลด์รูปอัตโนมัติ — [เพิ่ม 18 ส.ค. ตามสเปกเจ้าของ]
   ===========================================================================
   แถวรูปแนวนอน เลื่อนเองทุก 4.5 วิ (ตัวเดินจังหวะ: assets/js/blocks.js)
   ใช้ scroll จริง + snap → ผู้ใช้ปัดนิ้วเองได้ด้วย ระบบเลื่อนต่อให้เอง */
.blk-slider {
  position: relative;
  margin: 16px 0;
  border-radius: 14px;
  overflow: hidden;
}
.blk-slider-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;          /* ซ่อนแถบเลื่อน — จังหวะอัตโนมัติคุมเอง */
  -webkit-overflow-scrolling: touch;
}
.blk-slider-track::-webkit-scrollbar { display: none; }
.blk-slider-item {
  flex: 0 0 100%;
  margin: 0;
  scroll-snap-align: center;
}
.blk-slider-item img {
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: cover;
  display: block;
}
/* จุดบอกตำแหน่งรูป — blocks.js เป็นคนเติม/อัปเดต */
.blk-slider-dots {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}
.blk-slider-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
}
.blk-slider-dots span.on { background: var(--gold, #d4af37); }

/* [เพิ่ม 24 ส.ค.] ช่องว่างรอใส่รูปในเทมเพลต — กรอบประให้เห็นชัดว่าตรงนี้ต้องเติมเอง */
.blk-image-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  margin: 16px 0;
  border: 2px dashed var(--gold-dim, #8a7128);
  border-radius: 12px;
  background: rgba(212, 175, 55, .04);
}
.blk-image-hint {
  color: var(--gold-dim, #8a7128);
  font-size: .95rem;
}

/* [เพิ่ม 24 ส.ค.] แบนเนอร์ที่ยังไม่ใส่รูปปก — บอกให้ชัดว่าตรงนี้ควรมีภาพปก
   ไม่ใช่ปล่อยเป็นกล่องดำเปล่าจนผู้เขียนไม่รู้ว่าต้องเติมอะไร */
.blk-hero-nobg {
  position: relative;
  border: 2px dashed var(--gold-dim, #8a7128);
  background-color: rgba(212, 175, 55, .04);
}
.blk-hero-cover-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .85rem;
  color: var(--gold-dim, #8a7128);
  white-space: nowrap;
  pointer-events: none;
}
