/* --- ตัวแปรสำหรับปรับขนาด --- */
:root {
  --header-height: 8vh;
  --sidebar-width: 35vw;
  --video-height: 350px;
}

/* Font Face Definition */
@font-face {
  font-family: "line_seed_sans_th";
  src: url("fonts/LINESeedSansTH-Regular.eot");
  src: local("LINESeedSansTH-Regular"),
    url("fonts/LINESeedSansTH-Regular.woff2") format("woff2"),
    url("fonts/LINESeedSansTH-Regular.woff") format("woff"),
    url("fonts/LINESeedSansTH-Regular.ttf") format("truetype"),
    url("fonts/LINESeedSansTH-Regular.svg#fontname") format("svg");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* Global Base Styles (Desktop Default) */
html,
body {
  background: #435363;
  font-family: "line_seed_sans_th", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-smoothing: antialiased;
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  /* Desktop: ป้องกัน Scrollbar */
}

/* 2. HEADER: Desktop Fixed Layout */
header {
  height: var(--header-height);
  background: #435363;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 15px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

header img {
  height: 45px;
  margin-right: 10px;
}

.header-text {
  display: flex;
  flex-direction: column;
}

.header-text p {
  margin: 0;
  text-align: left;
  line-height: 1.1;
}

.thai-text {
  font-size: 1.5em;
  font-weight: bold;
}

.english-text {
  font-size: 80%;
  font-weight: normal;
  color: rgba(255, 255, 255, 0.53);
}

/* 1. MAP: Desktop Fixed Layout */
#map {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: var(--sidebar-width);
  bottom: 0;
  width: calc(100vw - var(--sidebar-width));
  height: calc(100vh - var(--header-height));
  z-index: 1;
  background: #ccc;
}

/* 3. SEARCH-BLOCK: Desktop Fixed Layout (Sidebar) */
#search-block-container {
  position: fixed;
  top: var(--header-height);
  right: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  z-index: 500;
  background: #435363;
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}

/* Video Container Styles (กระชับแล้ว) */
#video-container video {
  width: 100%;
  height: 100%;
  display: block;
}

/* Search block Styles */
#search-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px;
  overflow: hidden;
}

/* Select List Styles */
#search-block .select-style {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#location_select {
  flex: 1;
  width: 100%;
  height: auto;
  min-height: 150px;
}

#clearSearch {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  display: none;
  padding: 0 5px;
  background: transparent;
  border: none;
}

/* Input Styles */
input {
  font-family: "line_seed_sans_th", sans-serif;
  color: #fff;
  font-size: 14px;
  background-color: #596573;
  border: 1px solid #8d97a1 !important;
  padding: 8px 12px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.075);
  margin: 0 !important;
  box-sizing: border-box;
  width: 100%;
}

/* Placeholder color (รวมชุดที่ซ้ำซ้อน) */
input::placeholder {
  color: #ccc;
  opacity: 1;
}

input:-moz-placeholder {
  color: #ccc;
  opacity: 1;
}

input::-moz-placeholder {
  color: #ccc;
  opacity: 1;
}

input:-ms-input-placeholder {
  color: #ccc;
}

input:focus {
  border-color: #d9d9d9 !important;
  outline: 0;
  /*
  border-color: #80bdff !important;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  */
}

/* Select/Option Styles */
select {
  font-family: "line_seed_sans_th", sans-serif;
  border: 1px solid #8d97a1 !important;
  background: #596573;
  color: #fff;
  font-size: 14px;
  padding: 5px;
  box-sizing: border-box;
  margin-top: 5px;
  cursor: pointer;
}

select:focus {
  border-color: #d9d9d9 !important;
  outline: 0;
  /*
  border-color: #80bdff !important;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  */
}

option {
  padding: 5px 0 0 5px;
  margin: 5px 0 0 0;
  cursor: pointer;
  background-color: #596573;
  color: #fff;
}

option:hover,
option:focus,
option:active,
option:checked {
  color: #fff;
  background: linear-gradient(#8d97a1, #8d97a1);
}

option:not(:checked) {
  background-color: #596573;
}

/* Leaflet Pop-up Styles */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  font-family: "line_seed_sans_th", sans-serif;
  font-size: 14px;
  color: #232323;
  font-weight: bold;
  background-color: rgba(238, 235, 228, 0.92);
  border-radius: 0;
}

.leaflet-popup-content {
  max-width: 300px;
  max-height: 40px;
}

.leaflet-popup-close-button {
  color: #8d97a1 !important;
}

.leaflet-tooltip {
  border-radius: 0;
}

/* Tooltip สำหรับขอบเขตตำบล */
.boundary-tooltip {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 4px;
  color: #333;
  font-family: "line_seed_sans_th", sans-serif;
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid #aaa;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
}

/* =====================================
   FIX ALIGNMENT: Selector next to label
   ===================================== */
.leaflet-control-layers-base label {
  font-family: "line_seed_sans_th", sans-serif;
  display: flex !important;
  align-items: center !important; /* ✅ ช่วยจัดให้ปุ่มอยู่กลางข้อความแนวตั้ง */
  flex-direction: row !important;
  gap: 6px !important;
  padding: 6px !important;
  font-size: 13px !important;
  cursor: pointer !important;
  border-radius: 6px !important;
  transition: background 0.15s ease !important;
}

.leaflet-control-layers-base label:hover {
  background: #f4f4f4 !important;
}

/* ✅ ปุ่ม selector ให้อยู่กึ่งกลางจริง ๆ */
.leaflet-control-layers-selector {
  width: 15px !important;
  height: 15px !important;
  margin-right: 5px !important;
  flex-shrink: 0 !important;
  position: relative !important;
  top: 3px !important; /* 👈 ดันขึ้นเล็กน้อยให้ตรงกลางกับตัวอักษร */
}

/* ✅ ข้อความ */
.leaflet-control-layers-base span {
  line-height: 1.3 !important; /* ลดเล็กน้อยเพื่อให้ alignment สมดุล */
  color: #333 !important;
  white-space: nowrap !important;
}

/* ==========================================================
        * TABLET VERSION (768px – 1024px)
        * ========================================================== */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  :root {
    --header-height: 4.5vh !important;
    --sidebar-width: 50vw;
    --header-height-tablet: calc(var(--header-height) + 2vh);
  }

  header {
    height: auto !important;
    padding-top: 1vh !important;
    padding-bottom: 1vh !important;
  }

  #search-block-container {
    width: var(--sidebar-width) !important;
    top: var(--header-height-tablet) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-tablet)) !important;
  }

  #map {
    right: var(--sidebar-width) !important;
    width: calc(100vw - var(--sidebar-width)) !important;
    top: var(--header-height-tablet) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-tablet)) !important;
  }
}
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  :root {
    --header-height: 4.5vh !important;
    --sidebar-width: 50vw;
    --header-height-tablet: calc(var(--header-height) + 4.5vh);
  }

  header {
    height: auto !important;
    padding-top: 1vh !important;
    padding-bottom: 1vh !important;
  }

  #search-block-container {
    width: var(--sidebar-width) !important;
    top: var(--header-height-tablet) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-tablet)) !important;
  }

  #map {
    right: var(--sidebar-width) !important;
    width: calc(100vw - var(--sidebar-width)) !important;
    top: var(--header-height-tablet) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-tablet)) !important;
  }
}

/* ==========================================================
        * MOBILE VERSION (≤1024px)
        * ========================================================== */
@media (max-width: 1024px) and (orientation: portrait) {
  :root {
    --header-height: 3vh;
  }

  header {
    height: auto !important;
    padding-top: 1vh !important;
    padding-bottom: 1vh !important;
  }

  .leaflet-tooltip {
    display: none !important;
  }

  .leaflet-control-layers-base label {
    display: flex !important;
    align-items: center !important; /* ยังคงจัดแนวกลาง */
    flex-direction: row !important;
    gap: 6px !important;
    padding: 6px !important;
    font-size: 14px !important;
  }

  .leaflet-control-layers-selector {
    width: 18px !important;
    height: 18px !important;
    top: 3px !important; /* 👈 ดันขึ้นนิดเพื่อให้กลางจริง */
  }

  .leaflet-control-layers-base span {
    font-size: 14px !important;
    line-height: 1.4 !important;
  }
}
@media (max-width: 1024px) and (orientation: landscape) {
  :root {
    --header-height: 4.5vh !important;
    --sidebar-width: 50vw;
    --header-height-mobile: calc(var(--header-height) + 10vh);
  }

  header {
    height: auto !important;
    padding-top: 1vh !important;
    padding-bottom: 1vh !important;
  }

  #search-block-container {
    width: var(--sidebar-width) !important;
    top: var(--header-height-mobile) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-mobile)) !important;
  }

  #map {
    right: var(--sidebar-width) !important;
    width: calc(100vw - var(--sidebar-width)) !important;
    top: var(--header-height-mobile) !important; /* ใช้ตัวแปรใหม่ */
    height: calc(100vh - var(--header-height-mobile)) !important;
  }
}

/* ==========================================================
        * MOBILE VERSION (≤767px)
        * รวม Base (576px) + S/M/L เดิม
        * ========================================================== */
@media (max-width: 767px) {
  /* Layout ปรับเป็น column */
  html,
  body {
    overflow-y: auto !important;
  }

  body {
    display: flex;
    flex-direction: column;
  }

  header {
    position: relative !important;
    order: -1;
    /* Header อยู่บนสุด */
    width: 100% !important;
    height: var(--header-height);
    margin-bottom: 0 !important;
  }

  /* Search Container */
  #search-block-container {
    order: 0;
    position: relative !important;
    top: auto !important;
    right: auto !important;
    width: 100% !important;
    height: auto !important;
    flex: 1;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ✅ Video responsive */
  #video-container {
    width: 100% !important;
    aspect-ratio: 16 / 9;
    flex-shrink: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* ✅ Disable the focus outline or "color focus" on elements within a Video.js player */
  .video-js *:focus {
    outline: none;
  }

  .video-js *:focus {
    box-shadow: none;
  }

  .video-js .vjs-control-bar button:focus,
  .video-js .vjs-menu-button:focus,
  .video-js .vjs-menu *:focus {
    outline: none;
    box-shadow: none;
  }

  .video-js *:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
  }

  /* ✅ Search block */
  #search-block {
    flex: none !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding: 2vh 10px !important;
    /* เว้นช่องไฟด้านในแทน */
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  #search-block .select-style {
    flex: none !important;
    display: block !important;
    overflow-y: visible !important;
    margin-top: 5px !important;
  }

  /* ✅ MAP responsive */
  #map {
    order: 1;
    flex: 1 !important;
    position: relative !important;
    width: 100% !important;
    top: auto !important;
    margin-top: 0 !important;
    display: block !important;
    z-index: 1 !important;
  }

  /* Input & Select */
  input,
  select {
    flex-shrink: 0 !important;
    padding: 8px 12px !important;
    box-sizing: border-box !important;
  }

  #location_select {
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    max-height: auto !important;
    padding: 9px 12px !important;
    margin-top: 5px !important;

    /* Custom Arrow */
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: url("data:image/svg+xml;utf8,<svg fill='%23ffffff' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>") !important;
    background-repeat: no-repeat !important;
    background-position: right 5px center !important;
    background-size: 24px 24px !important;
    padding-right: 25px !important;
  }

  /* Header text scale */
  .thai-text {
    font-size: 1.4em !important;
  }

  .english-text {
    font-size: 70% !important;
    color: rgba(255, 255, 255, 0.53);
  }
}
