/* =========================
   GLOBAL
   ========================= */
html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Prompt', sans-serif;
  background: #FCF8F3;
  overflow: hidden;
}

/* =========================   
 HEADER (TerraRice CLEAN)    
========================= */ 
.app-header {   
  background: #1B5E20;   
  color: #FFD700;   
  width: 100%;   
  display: flex;   
  flex-direction: column;   
  gap: 0;
  padding: 0px 20px 0px 20px;
  box-sizing: border-box;
  position: relative;  
  z-index: 1000;  
}

.header-top {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: -25px;  
}

.app-header .logo-img {
  height: 150px;
  width: auto;
  flex: 0 0 auto;
  transform: translate(-20px, -2px);
}

.title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
  margin-left: -30px;
  margin-top: -2px;
  margin-bottom: 0;
}

.app-name {
  font-size: 42px;
  font-weight: 600;
  line-height: 0.95;
  margin: 0;          
  color: #ffd700;
}

.subtitle-th {
  font-size: 16px;
  line-height: 1.2;
  color: #FFF3B0;
}

.subtitle-en {
  font-size: 16px;
  line-height: 1.2;
  color: #FFF3B0;
  opacity: 0.95;
}

/*dropdown*/
.menu-toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: none;
  color: #FFD700;
  font-size: 28px;
  cursor: pointer;
  padding: 6px 8px;
}

/* Row 2 */
.header-bottom {
  width: 100%;
  margin-left: auto;
  padding-top: 0px;
  padding-bottom: 8px;  
}
.app-header .controls {
  padding-top: 0;
  margin-top: 0;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.app-header .controls select {
  padding: 7px 12px;  
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid #FFD700;
  background: #FFFFFF;
  cursor: pointer;
  min-width: 110px;
  color: #1B5E20;
}

.reset-btn {
  padding: 7px 12px;  
  font-size: 14px;
  border-radius: 10px;
  border: none;
  background: #D35400;
  color: #FFFFFF;
  cursor: pointer;
  font-weight: 500;
}

.reset-btn:hover {
  background: #E67E22;
}


/* กลุ่มโลโก้มุมขวาบน */
.header-right-logos {
  position: absolute;
  top: -15px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;            
}

.header-right-logos img {
  height: 150px;
  width: auto;
  object-fit: contain;

  /* เพิ่มเงา */
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.35));
}

/*คำอธิบายคะแนน s1-N*/
.suitability-criteria {
  font-size: 13px;
  line-height: 1.5;
  color: #2e2e2e;
  margin-top: 10px;
}

.suitability-criteria h4 {
  margin: 8px 0;
  font-size: 14px;
  color: #1B5E20;
  font-weight: 600;
}

.criteria-list {
  padding-left: 16px;
  margin: 6px 0;
}

.criteria-list li {
  margin-bottom: 8px;
}

.criteria-note {
  font-size: 12px;
  margin-top: 8px;
  color: #555;
}



/* =========================
   MOBILE HEADER (Improved)
   ========================= */
@media (max-width: 768px) {

  .app-header {
    padding: 8px 18px 10px 18px;  
  }

  .header-top {
    display: flex;
    align-items: flex-start;  
    justify-content: space-between;
    gap: 12px;
    min-height: 68px;
    padding-top: 4px;  
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    padding: 4px 6px;  
    min-width: 44px;
    margin-top: 0;  
  }

  .subtitle-th,
  .subtitle-en {
    display: none;
  }

  .header-bottom {
    display: none;
  }

  .header-bottom.active {
    display: block;
    margin-top: 10px;
    padding-bottom: 10px;
  }

  .app-header .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .app-header .controls select,
  .app-header .controls button {
    width: 100%;
    min-height: 46px;
    font-size: 15px;
    padding: 10px 14px;
  }

  .app-header .logo-img {
    height: 50px;
    width: auto;
    transform: none;      
    margin-right: 10px;
    margin-top: 0;  
  }

  .title-group {
    margin: 0;
    margin-left: -5px;
    margin-top: 4px;  
    flex: 1;
  }

  .app-name {
    font-size: 22px;
    line-height: 1.2;
    font-weight: 600;
  }

  .app-container {
    height: calc(100vh - 130px);
  }
}

/* =========================
   LAYOUT
   ========================= */
.app-container {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 130px);  
  overflow: hidden;
}

/* =========================
   SIDEBAR
   ========================= */
.side-panel.left {
  background: #fff;
  padding: 5px 14px 14px 14px;
  font-size: 18px;
  border-right: 1px solid #E0D5C1;
  overflow-y: auto;
}

.side-panel.left h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #086d0e;
}

.side-panel.left label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  cursor: pointer;
}

/* Sidebar toggle (mobile) */
.toggle-sidebar {
  position: absolute;
  right: -35px;
  top: 20px;
  width: 35px;
  height: 50px;
  background: #1B5E20;
  color: white;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: none;
  z-index: 2001;
}
/* =========================
   MAP
   ========================= */
.map-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  position: relative;  
}

/*แสดง attribution */
.leaflet-control-attribution {
  display: block !important;
  background: rgba(255, 255, 255, 0.8) !important;
  padding: 2px 5px !important;
  font-size: 11px !important;
}


/* =========================
   MOBILE LAYOUT
   ========================= */
@media (max-width: 768px) {
  .app-container {
    display: block;
    position: relative;
    height: 100vh;  
    width: 100vw;  
  }
  .header-right-logos {
    display: none;
  }


  .map-wrapper {  
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  #map {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100% !important;  
    height: 100% !important;  
  }

  .side-panel.left {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 2000;
    background: #fff;
  }

  .side-panel.left.active {
    transform: translateX(0);
  }

  .toggle-sidebar {
    display: block;
  }


   .sidebar.left {
    display: none;
  }

  /* bottom sheet */
  .mobile-sheet {
    position: fixed;
    left: 0;
    bottom: -70%;
    width: 100%;
    height: 70%;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
    transition: bottom 0.3s ease;
    z-index: 9999;
  }

  .mobile-sheet.active {
    bottom: 0;
  }

  .sheet-handle {
    width: 40px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 10px auto;
  }

  .sheet-content {
    overflow-y: auto;
    height: calc(100% - 30px);
    padding: 12px;
  }
}


/* ปุ่มเปิดแผง (โชว์เฉพาะมือถือ) */
.sheet-btn{
  display:none;
}

@media (max-width: 768px){
  .sheet-btn{
    display:block;
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 10002;
    padding: 10px 12px;
    border: none;
    border-radius: 12px;
    background: #1B5E20;
    color: #fff;
    font-family: 'Prompt', sans-serif;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  }

  .mobile-sheet{
    position: fixed;
    left: 0;
    bottom: -70%;
    width: 100%;
    height: 70%;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
    transition: bottom 0.25s ease;
    z-index: 10001;
  }

  .mobile-sheet.active{
    bottom: 0;
  }

  .sheet-handle{
    width: 42px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 10px auto;
  }

  .sheet-content{
    height: calc(100% - 28px);
    overflow-y: auto;
    padding: 12px 14px 18px;
    box-sizing: border-box;
  }
}


/* =========================
   NPK / pH PANEL (RESTORE)
   ========================= */

/* pH gauge box */
.ph-gauge-box {
  width: 100%;
  max-width: 280px;
  background: #FAF3E0;
  padding: 15px;
  border-radius: 20px;
  text-align: center;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.05);
  margin: 10px auto;
  box-sizing: border-box;
}

.ph-gauge-box .gauge-title {
  font-size: 1.1rem;
  color: #42443e;
  font-weight: 700;
  margin: 0 0 15px 0;
}

#ph-value {
  font-size: 1.1rem;
  color: #3E2A14;
  font-weight: 700;
  margin-top: 10px;
}

/* gauge */
.gauge {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
}

.gauge__body {
  width: 180px;
  height: 90px;
  background: #E0D5C1;
  position: relative;
  border-top-left-radius: 90px;
  border-top-right-radius: 90px;
  overflow: hidden;
}

.gauge__color-map {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    #ff4d4d 0%, #ffa500 25%, #ffff00 45%,
    #2ecc71 50%, #00d2ff 65%, #3498db 85%, #9b59b6 100%);
}

.gauge__cover {
  width: 130px;
  height: 65px;
  background: #FAF3E0;
  border-top-left-radius: 65px;
  border-top-right-radius: 65px;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
}

.gauge__needle {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 3px;
  height: 80px;
  background: #3E2A14;
  transform-origin: bottom center;
  transform: translateX(-50%) rotate(-90deg);
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 5;
}
.gauge__needle::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 10px;
  height: 10px;
  background: #3E2A14;
  border-radius: 50%;
  transform: translateX(-50%);
}

/* nutrients container */
.soil-nutrients-container {
  background: #FAF3E0;
  padding: 15px 10px;
  border-radius: 20px;
  text-align: center;
  box-sizing: border-box;
}

.soil-nutrients-container h4 {
  margin: 0 0 15px 0;
  color: #42443e;
  font-size: 1.1rem;
  font-weight: 700;
}

.nutrients-grid {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  gap: 8px;
}

.nutrient-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 85px;
}

.progress-ring-wrapper {
  position: relative;
  width: 70px;
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 8px;
}

.progress-ring__circle {
  transition: stroke-dashoffset 0.8s ease-in-out, stroke 0.3s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke-dasharray: 175.93;
  stroke-dashoffset: 175.93;
}

.nutrient-value {
  position: absolute;
  width: 100%;
  text-align: center;
  font-weight: 800;
  font-size: 0.75rem;
  color: #3E2A14;
  margin: 0;
}

.nutrient-label {
  font-weight: 800;
  font-size: 0.75rem;
  color: #3E2A14;
  margin-top: 4px;
  white-space: nowrap;
}

/* advice area */
.advice-box {
  margin-top: 12px;
}

.advice-group {
  margin-bottom: 15px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #E0D5C1;
}

.fertilizer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.fertilizer-table th {
  text-align: center;
  color: #8B5A2B;
  padding: 6px;
  border-bottom: 1px solid #E0D5C1;
  font-size: 0.75rem;
}

.fertilizer-table td {
  padding: 6px;
  text-align: center;
  font-weight: 800;
  color: #3E2A14;
}

/* soil section */
.soil-section {
  margin: 12px 0;
  padding: 16px;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid #E0D5C1;
  border-left: 6px solid #8B5A2B;
  box-shadow: 0 4px 12px rgba(139, 90, 43, 0.08);
  text-align: left;
}

.soil-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #5A3A1A;
  margin-bottom: 8px;
}

/* cards */
.soil-info-container {
  font-family: 'Prompt', sans-serif;
  padding: 15px;
  box-sizing: border-box;
  width: 100%;
}

.info-card {
  width: 100%;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 18px;
  background-color: #ffffff;
  border: 1px solid #E0D5C1;
  box-shadow: 0 4px 12px rgba(139, 90, 43, 0.08);
  box-sizing: border-box;
}

.restriction-card {
  background-color: #FDF2E9;
  border-left: 6px solid #D35400;
}
.restriction-header {
  margin-bottom: 8px;
  color: #A04000;
  font-weight: 800;
  font-size: 1rem;
  text-align: left;
}

.recommendation-card {
  background-color: #E8F5E9;
  border-left: 6px solid #1B5E20;
}
.recommendation-header {
  margin-bottom: 8px;
  color: #1B5E20;
  font-weight: 800;
  font-size: 1rem;
  text-align: left;
}

.card-text {
  font-size: 14px;
  line-height: 1.6;
  color: #3E2A14;
  text-align: left;
}

/* แก้พื้นหลัง Nutrients ให้โอบข้อความทั้งหมด */
.nutrients-grid {
  align-items: stretch;
}

#openSheet {
  position: fixed !important;
  bottom: 20px !important;
  left: 20px !important;  
  right: auto !important;
}

/* ===================================================
   FLOATING SUITABILITY BOX (Mobile Drawer)
   =================================================== */

@media (max-width: 768px) {
  #floatingSuitBox {
    position: fixed;
    top: 180px; 
    left: 0;
    z-index: 10005; /* มั่นใจว่าอยู่เหนือแผนที่ */
    background: white;
    padding: 15px 25px 15px 10px; /* เพิ่ม padding ขวาเล็กน้อย */
    border-radius: 0 16px 16px 0;
    box-shadow: 4px 0 15px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* ซ่อนไว้ทางซ้าย */
    transform: translateX(-100%); 
    
    /* สำคัญ: ป้องกันกล่องที่ซ่อนอยู่ไปขวางการจิ้มแผนที่ */
    pointer-events: none; 
  }

  /* เมื่อ Active (เปิดออกมา) */
  #floatingSuitBox.active {
    transform: translateX(0);
    pointer-events: auto; /* ให้กลับมาจิ้ม Checkbox ได้ */
  }

  /* ปุ่มลูกศรที่ยื่นออกมา */
  #floatingSuitBox::after {
    content: '❯'; 
    position: absolute;
    right: -35px; /* ดันปุ่มยื่นออกไปนอกขอบกล่อง */
    top: 0;
    width: 35px;
    height: 50px;
    background: #1B5E20;
    color: #FFD700;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    font-size: 20px;
    box-shadow: 3px 0 8px rgba(0,0,0,0.2);
    
    /* สำคัญ: ทำให้ปุ่มนี้กดได้ตลอดเวลาแม้ตัวกล่องจะติดลบ 100% */
    pointer-events: auto; 
  }

  /* เปลี่ยนลูกศรเมื่อเปิด */
  #floatingSuitBox.active::after {
    content: '❮';
  }

  /* ปรับแต่ง Label ให้จิ้มง่ายขึ้น (Touch Target) */
  #floatingSuitBox label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 500;
    color: #3E2A14;
    cursor: pointer;
    white-space: nowrap;
    padding: 4px 0; /* เพิ่มพื้นที่ให้ปลายนิ้วจิ้มง่าย */
  }

  #floatingSuitBox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #1B5E20;
    margin: 0;
  }
}

@media (min-width: 769px) {
  #floatingSuitBox {
    display: none;
  }
}
