/* ============================================================
   esa_map.css : แผนที่สาขาวิชาเอกที่เปิดสอบ แยกตามเขตพื้นที่ (esa_map.js / esa_map_lib.php)
   ------------------------------------------------------------
   ใช้ทั้งหน้าแรก index.php (home.css) และ report_obec/index.php (year_admin.css)
   ทุกคลาสขึ้นต้น em- และตั้งค่าเองทั้งหมด (สี / ฟอนต์ / ปุ่ม / ช่องเลือก) ไม่พึ่งสไตล์ของหน้า
     .em-card   กล่องนอกสุด (id="em")  มีตัวแปรสีทั้งหมด
     .em-seg    ปุ่มสลับ สพป. / สพม. (แต่ละหน้าวางไว้ที่หัวการ์ดของตัวเอง)
     .em-body   ช่องเลือก + แผนที่ + รายละเอียด
     .em-tip    กล่องข้อมูลลอยตามเมาส์ (อยู่ใต้ body จึงใส่สีตรง ๆ)
   --em-top  ระยะจากขอบบนจอตอนแผนที่ลอยตามการเลื่อนหน้า (หน้าที่มีเมนูลอยด้านบนตั้งให้มากขึ้น)
   ============================================================ */

.em-card {
    --em-gold: #D6B172;
    --em-gold-dark: #a8844a;
    --em-gold-soft: rgba(214, 177, 114, .16);
    --em-cream: #faf4eb;
    --em-ink: #1f1f1f;
    --em-muted: #8d8d8d;
    --em-dim: #857d70;
    --em-line: #eee4d3;
    --em-green: #1f9d55;
    --em-red: #e05b5b;
    --em-top: 10px;
}
.em-card *, .em-tip { box-sizing: border-box; }

/* ---------- ปุ่มสลับ สพป. / สพม. ---------- */
.em-seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: 999px; background: #f5efe4; }
.em-seg button { min-height: 0; margin: 0; padding: 6px 16px; border: 0; border-radius: 999px; background: transparent; color: #6b604f;
                 font-family: inherit; font-size: 14px; font-weight: 400; line-height: 1.5; cursor: pointer; }
.em-seg button:hover { background: rgba(255, 255, 255, .6); color: var(--em-ink); }
.em-seg button.on { background: #fff; color: var(--em-ink); font-weight: 500; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- ช่องเลือกสาขา / เขต ---------- */
.em-body { color: var(--em-ink); font-size: 15px; line-height: 1.6; text-align: left; }
.em-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 0 0 18px; }
.em-f { display: flex; align-items: center; gap: 10px; flex: 1 1 300px; min-width: 0; margin: 0; font-size: 13px; color: var(--em-dim); }
.em-f span { white-space: nowrap; }
.em-f select { flex: 1; min-width: 0; width: 100%; margin: 0; padding: 9px 14px; border: 1px solid var(--em-line); border-radius: 12px;
               background: #fff; color: var(--em-ink); font-family: inherit; font-size: 15px; line-height: 1.4; cursor: pointer;
               transition: border-color .15s, box-shadow .15s; }
.em-f select:focus { outline: none; border-color: var(--em-gold); box-shadow: 0 0 0 3px rgba(214, 177, 114, .25); }

/* ---------- แผนที่ ---------- */
.em-grid { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 30px; align-items: start; }
/* สูงไม่เกินราว 80% ของจอ : จำกัดความกว้างแทน (แผนที่คงสัดส่วนตาม viewBox) */
.em-mapbox { position: sticky; top: var(--em-top); width: 100%; max-width: min(440px, 44vh); min-width: 240px; margin: 0 auto; }
.em-map { position: relative; border: 1px solid var(--em-line); border-radius: 16px; background: #f2f6f8; overflow: hidden;
          aspect-ratio: 4894 / 8952; }   /* = w / h ใน th_esa_map.js : จองที่ไว้ก่อนสคริปต์วาด */
.em-svg { display: block; width: 100%; height: auto; touch-action: pan-y; cursor: pointer; -webkit-user-select: none; user-select: none; }
.em-map.zoomed .em-svg { touch-action: none; }
.em-map.drag .em-svg { cursor: grabbing; }
.em-svg path { vector-effect: non-scaling-stroke; }
.em-svg pattern path { vector-effect: none; }   /* ลายเส้นรอประกาศ ย่อ/ขยายด้วย patternTransform เอง */
.em-m { fill: none; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.em-m.amp { stroke: #fff; stroke-width: .5; opacity: .8; }        /* อำเภอในเขตเดียวกัน */
.em-m.inner { stroke: #fff; stroke-width: 1; stroke-dasharray: 3 3; }   /* จังหวัดใน สพม. เดียวกัน */
.em-m.esa { stroke: #fff; stroke-width: 1.1; }                     /* ระหว่างเขต */
.em-m.prov { stroke: #fff; stroke-width: 1.9; }                    /* ระหว่างจังหวัด */
.em-m.out { stroke: #b5a17c; stroke-width: .8; }                   /* ขอบประเทศ / ชายฝั่ง */
.em-hov { fill: none; stroke: #3a2c14; stroke-width: 1.3; stroke-linejoin: round; pointer-events: none; }
.em-sel { fill: none; stroke: #3a2c14; stroke-width: 2.6; stroke-linejoin: round; pointer-events: none; }
.em-lbl { font-family: inherit; font-weight: 600; fill: #3a2c14; stroke: #fff; stroke-linejoin: round; paint-order: stroke;
          text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.em-zoom { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.em-zb { display: grid; place-items: center; width: 34px; height: 34px; margin: 0; padding: 0; border: 1px solid var(--em-line); border-radius: 10px;
         background: #fff; color: var(--em-ink); font-size: 14px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
         transition: border-color .15s, background .15s; }
.em-zb:hover { border-color: var(--em-gold); background: var(--em-cream); }
.em-zb:disabled { opacity: .4; cursor: default; border-color: var(--em-line); background: #fff; }
.em-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: calc(100% - 24px); padding: 8px 14px;
           border-radius: 12px; background: rgba(31, 31, 31, .8); color: #fff; font-size: 13px; text-align: center; pointer-events: none;
           opacity: 0; transition: opacity .25s; }
.em-hint.on { opacity: 1; }
.em-pick { display: none; }

/* คำอธิบายสี */
.em-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--em-muted); }
.em-legend .g { display: flex; align-items: center; gap: 8px; flex: 1 1 100%; }
.em-legend .g i { flex: 1; height: 10px; border-radius: 6px; }
.em-legend .g em { font-style: normal; }
.em-legend .s { display: inline-flex; align-items: center; gap: 6px; }
.em-legend .s i { width: 13px; height: 13px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.em-legend .s i.wait { background: repeating-linear-gradient(-45deg, #d9d6d0 0 1.5px, #f4f3f1 1.5px 5px); }
.em-credit { margin: 6px 0 0; font-size: 11px; font-weight: 300; color: var(--em-muted); }
.em-credit a { color: var(--em-gold-dark); text-decoration: none; }
.em-credit a:hover { text-decoration: underline; }
.em-help { margin: 16px 0 0; font-size: 13px; font-weight: 300; line-height: 1.6; color: var(--em-muted); }

/* ---------- กล่องข้อมูลลอยตามเมาส์ ---------- */
.em-tip { position: fixed; z-index: 120; display: none; pointer-events: none; max-width: 270px; padding: 8px 12px; border: 1px solid #eee4d3;
          border-radius: 12px; background: #fff; color: #1f1f1f; font-size: 13px; line-height: 1.55; text-align: left;
          box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
.em-tip b { font-weight: 600; }
.em-tip .m { color: #8d8d8d; font-size: 12px; }
.em-tip .em-badge { font-size: 12px; padding: 1px 9px; margin-top: 3px; }

/* ---------- ป้าย / ปุ่มเล็ก ---------- */
.em-tp { display: inline-grid; place-items: center; flex: none; min-width: 48px; height: 28px; padding: 0 8px; border-radius: 9px; font-size: 13px; font-weight: 600; }
.em-tp1 { background: rgba(214, 177, 114, .16); color: #a8844a; }
.em-tp2 { background: #D6B172; color: #1f1f1f; }
.em-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 13px; white-space: nowrap; background: #f3f3f3; color: #888; }
.em-badge.ok { background: rgba(31, 157, 85, .1); color: #1f9d55; }
.em-badge.unof { background: rgba(214, 177, 114, .16); color: #a8844a; }
.em-badge.closed { background: rgba(255, 105, 105, .12); color: #e05b5b; }
.em-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 30px; margin: 0; padding: 0 12px;
          border: 1px solid var(--em-line); border-radius: 999px; background: #fff; color: var(--em-ink); font-family: inherit; font-size: 13px;
          font-weight: 500; line-height: 1.2; white-space: nowrap; text-decoration: none; cursor: pointer; transition: background .2s, border-color .2s; }
.em-btn:hover { background: var(--em-cream); border-color: var(--em-gold); color: var(--em-ink); text-decoration: none; }
.em-ico { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; margin: 0; padding: 0; border: 1px solid var(--em-line);
          border-radius: 50%; background: #fff; color: var(--em-gold-dark); font-family: inherit; font-size: 14px; cursor: pointer; transition: all .2s; }
.em-ico:hover { border-color: var(--em-gold); background: var(--em-cream); }

/* ---------- รายละเอียดด้านข้าง ---------- */
.em-detail { min-width: 0; scroll-margin-top: calc(var(--em-top) + 6px); }   /* ลิงก์ "ดูสาขา" เลื่อนมาแล้วไม่มุดใต้เมนูลอย */
.em-dh { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.em-dh h3 { flex: 1; min-width: 0; margin: 0; padding: 0; border: 0; font-size: 19px; font-weight: 500; line-height: 1.35; color: var(--em-ink); }
.em-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 10px; font-size: 13px; color: #666; line-height: 1.6; }
.em-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.em-kpis .k { min-width: 0; padding: 9px 12px; border: 1px solid var(--em-line); border-radius: 12px; background: #fffdf9; }
.em-kpis .k b { display: block; font-size: 22px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.em-kpis .k span { display: block; font-size: 12px; color: var(--em-muted); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.em-kpis .k.hl { background: var(--em-gold-soft); border-color: var(--em-gold); }
.em-kpis .k.hl b { color: var(--em-gold-dark); }
.em-detail h4 { margin: 0 0 6px; padding: 0; font-size: 14px; font-weight: 500; color: var(--em-gold-dark); }
.em-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(50px, 1fr) 44px; gap: 12px; align-items: center; width: 100%; min-height: 0;
          margin: 0; padding: 6px 8px; border: 0; border-radius: 10px; background: none; color: var(--em-ink); font-family: inherit; font-size: 14px;
          font-weight: 400; line-height: 1.45; text-align: left; cursor: pointer; }
.em-row:hover { background: #fffaf2; }
.em-row.on { background: var(--em-gold-soft); }
.em-row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.em-row .b { height: 8px; border-radius: 6px; background: #f3eee6; overflow: hidden; }
.em-row .b i { display: block; height: 100%; border-radius: 6px; background: var(--em-gold); }
.em-row.on .b i { background: var(--em-gold-dark); }
.em-row b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.em-row.un { cursor: default; color: var(--em-muted); }
.em-row.un:hover { background: none; }
.em-row.un .b i { background: #d8d1c4; }
.em-more { margin-top: 8px; }
.em-go { margin: 14px 0 0; }
.em-note { margin: 10px 0 0; font-size: 13px; color: var(--em-muted); }

/* ---------- จอแคบ ---------- */
@media (max-width: 900px) {
    .em-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
    .em-mapbox { position: static; max-width: min(440px, 100%, 62vh); }
    /* กล่องรายละเอียดอยู่ใต้แผนที่ : แถบบอกเขตที่เลือก + ลิงก์เลื่อนลงไปดูสาขา */
    .em-pick.on { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
                  padding: 8px 12px; border: 1px solid var(--em-line); border-radius: 12px; background: rgba(255, 255, 255, .95); font-size: 13px;
                  box-shadow: 0 4px 14px rgba(0, 0, 0, .1); }
    .em-pick span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .em-pick b { font-weight: 600; }
    .em-pick a { flex: none; color: var(--em-gold-dark); font-weight: 500; text-decoration: none; }
}
@media (max-width: 600px) {
    .em-f select { font-size: 16px; }   /* iPhone ไม่ซูมหน้าเองตอนแตะช่องเลือก */
}

/* ภาพรวม / รายละเอียดข้างแผนที่ บนมือถือ : ตัวเลข 3 ช่องแถวเดียว เตี้ย ๆ ประหยัดพื้นที่ (2026-09-29) */
@media (max-width: 600px) {
    .em-dh h3 { font-size: 18px; }
    .em-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0 12px; }
    .em-kpis .k { padding: 6px 8px; border-radius: 10px; }
    .em-kpis .k b { font-size: 18px; line-height: 1.25; }
    .em-kpis .k span { font-size: 10.5px; }
}

/* ปุ่มสลับ + ช่องเลือกสาขา / เขต บนมือถือ : กะทัดรัด (2026-09-29)
   ปุ่ม สพป. / สพม. แบ่งครึ่งเต็มความกว้าง · ป้ายชื่อช่องกว้างเท่ากัน ตัวเล็ก · ช่องเลือกเตี้ยลง (ตัวอักษร 16px กัน iPhone ซูม) */
@media (max-width: 600px) {
    .em-seg { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
    .em-seg button { padding: 5px 8px; font-size: 13px; }
    .em-bar { gap: 6px; margin: 0 0 12px; }
    .em-f { flex-basis: 100%; gap: 8px; font-size: 11.5px; }
    .em-f span { flex: none; width: 58px; font-weight: 500; color: var(--em-gold-dark); }
    .em-f select { padding: 5px 10px; border-radius: 10px; line-height: 1.3; }
}
