/* responsive.css - dasar responsif & mudah dipakai (berlaku di semua tema) */
main section,main article{min-width:0}
.overflow-x-auto{-webkit-overflow-scrolling:touch}
:focus-visible{outline:3px solid rgba(40,122,77,.55);outline-offset:2px}
.kk-tab-ic{display:none}
@media (max-width:1023px){
  #map{height:min(58vh,460px)}
  main{padding:.75rem !important}
  .tab-button{min-height:44px}
}
@media (max-width:767px){
  input,select,textarea{font-size:16px !important;min-height:44px}
  button,.hs-kws-mode{min-height:40px}
  header.sticky h1{font-size:.82rem !important;line-height:1.2}
  header.sticky p.text-xs{display:none}
  header.sticky img{height:2rem !important}
  header.sticky>div:first-child{padding:.5rem .75rem !important;gap:.5rem !important}
  #summaryCards{grid-template-columns:repeat(2,minmax(0,1fr)) !important;gap:.6rem !important}
  h2.text-2xl{font-size:1.25rem !important}
  /* navigasi bawah (bottom tab bar) */
  header.sticky nav{position:fixed;left:0;right:0;bottom:0;z-index:50;max-width:none !important;padding:0 !important;gap:0 !important;overflow:visible;
    background:#fff;border-top:1px solid #dbe5df;box-shadow:0 -8px 24px -12px rgba(11,41,27,.3);padding-bottom:env(safe-area-inset-bottom) !important}
  .tab-button{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
    padding:.45rem .1rem !important;font-size:.62rem !important;line-height:1.1;white-space:normal !important;text-align:center;
    border:0 !important;border-radius:0 !important;margin:0 !important;background:transparent !important;color:#64748b !important;box-shadow:none !important}
  .tab-button.hidden{display:none !important}
  .tab-button.active{color:#174d31 !important;font-weight:800;background:#effaf3 !important}
  .kk-tab-ic{display:block;font-size:1.15rem}
  main{padding-bottom:5.5rem !important}
  #toast{bottom:5rem !important}
}

/* ---- Matriks Kawasan x Tanggal: kolom beku diperkecil agar kolom TANGGAL terlihat ---- */
#matrixHead .matrix-header-date{color:#334155 !important;font-size:11px;font-weight:700;white-space:nowrap}
.matrix-table .matrix-col-nupt{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.matrix-table .matrix-col-nkws{white-space:normal;line-height:1.25}
@media (max-width:1599px){
  html .matrix-table .matrix-col-nupt,html #matrixHead .matrix-header-nupt{left:0 !important;width:84px !important;min-width:84px !important;max-width:84px;padding:.5rem !important}
  html .matrix-table .matrix-col-nkws,html #matrixHead .matrix-header-nkws{left:84px !important;width:150px !important;min-width:150px !important;padding:.5rem !important}
}
@media (max-width:767px){
  /* NUPT ikut tergulir; hanya NKWS yang menempel di kiri */
  html .matrix-table .matrix-col-nupt{position:static !important;width:72px !important;min-width:72px !important;max-width:72px}
  html #matrixHead .matrix-header-nupt{position:sticky !important;left:auto !important;width:72px !important;min-width:72px !important;max-width:72px}
  html .matrix-table .matrix-col-nkws,html #matrixHead .matrix-header-nkws{left:0 !important;width:112px !important;min-width:112px !important;font-size:11px}
  html .matrix-table .matrix-cell,html #matrixHead .matrix-header-date{min-width:48px !important;width:48px !important}
  html #matrixHead .matrix-header-nupt{z-index:20 !important}
}
html.kk-c #matrixScrollContainer{background:#101d17 !important}
html.kk-c .matrix-table .matrix-col-nupt,html.kk-c .matrix-table .matrix-col-nkws{background-color:#101d17 !important;color:#eef6f1 !important}
html.kk-c #matrixHead th{background-color:#16271f !important;color:#cfe3d6 !important}

/* ---- Anti-geser-samping di HP: halaman tidak boleh lebih lebar dari layar ---- */
@media (max-width:767px){
  html{overflow-x:hidden !important}
  body{max-width:100vw;position:relative}
  header.sticky,main{max-width:100vw !important;box-sizing:border-box}
  /* item grid/flex boleh menyusut (penyebab umum halaman melebar karena tabel min-w-max) */
  :where(main .grid)>*{min-width:0}
  main section,main article,main .view>*{min-width:0;max-width:100%}
  main .grid:not(#summaryCards){grid-auto-columns:minmax(0,1fr)}
  main canvas{max-width:100% !important}
  main :where(.overflow-x-auto,.matrix-scroll-container){max-width:100%;overflow-x:auto}
  main table:not(#matrixTable){max-width:100%}
  main :where(td,th) .rounded-full{white-space:nowrap}
  main :where(.flex-wrap){row-gap:.5rem}
  /* menu bawah: grid agar 5 tab selalu sama lebar & pas layar */
  html header.sticky nav{display:grid !important;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);width:100%;box-sizing:border-box}
  html header.sticky nav .tab-button{min-width:0;overflow:hidden;word-break:break-word}
  #kkThemeBox{max-width:calc(100vw - 24px)}
}

/* ---- Badge "Jenis SK" & pil dalam tabel: jangan pecah dua baris (semua ukuran layar) ---- */
main table td span.rounded-full,main table td .rounded-full{display:inline-block;white-space:nowrap;line-height:1.25}
#mpaBody td:nth-child(3){min-width:150px;white-space:nowrap}

/* ---- Menu dropdown (Ekspor PDF/Excel): jangan terpotong di sisi layar ---- */
.dpr-menu>div[id$=Menu]{max-width:calc(100vw - 24px)}
@media (max-width:767px){
  /* tampil sebagai panel bawah, tidak menimpa tombol/isi tabel */
  .dpr-menu>div[id$=Menu]:not(.hidden){position:fixed !important;left:12px !important;right:12px !important;top:auto !important;bottom:5.75rem !important;
    width:auto !important;max-width:none;max-height:68dvh;overflow-y:auto;z-index:70 !important;margin:0 !important;box-shadow:0 -10px 40px -8px rgba(0,0,0,.45) !important}
  /* toolbar filter/aksi: tersusun rapi, lebar penuh */
  main .view .flex.flex-wrap.items-center.gap-2{width:100%}
  main .view .flex.flex-wrap.items-center.gap-2>input,main .view .flex.flex-wrap.items-center.gap-2>select{flex:1 1 100%;width:100%}
  main .view .flex.flex-wrap.items-center.gap-2>.dpr-menu,main .view .flex.flex-wrap.items-center.gap-2>button{flex:1 1 42%}
  main .view .flex.flex-wrap.items-center.gap-2>.dpr-menu>button{width:100%}
  main .view .flex.flex-wrap.items-center.gap-2>button{justify-content:center}
  /* tabel SDM: kolom tidak terjepit, kolom nama UPT menempel saat digeser */
  #view-dpr-detail table{min-width:760px}
  #view-dpr-detail table th:first-child{position:sticky;left:0;z-index:3;background:#fef3c7;min-width:150px}
  #view-dpr-detail table td:first-child{position:sticky;left:0;z-index:2;background:#fff;min-width:150px;box-shadow:6px 0 8px -6px rgba(15,23,42,.18)}
  /* tombol Tampilan: ikon saja agar tidak menutupi isi */
  #kkThemeBox>button:last-child{width:44px;height:44px;padding:0 !important;display:flex !important;align-items:center;justify-content:center;opacity:.92}
  #kkThemeBox .kk-lbl{display:none}
}
html.kk-c #view-dpr-detail table td:first-child{background:#101d17}
html.kk-c #view-dpr-detail table th:first-child{background:#16271f}

/* =====================================================================
   MODAL / FORM / POPUP - seragam & nyaman di semua ukuran layar
   ===================================================================== */
@keyframes kkSheet{from{transform:translateY(24px);opacity:.6}to{transform:none;opacity:1}}
@keyframes kkPop{from{transform:scale(.96);opacity:.5}to{transform:none;opacity:1}}
@keyframes kkFade{from{opacity:0}to{opacity:1}}
.app-modal:not(.hidden),#dprModal:not(.hidden),#coordWarnModal:not(.hidden){animation:kkFade .15s ease-out;overscroll-behavior:contain}
.app-modal-panel,#dprModal>div,#coordWarnModal>div{max-height:calc(100dvh - 2rem)}
.app-modal-panel{overflow-y:auto}
/* tombol tutup (×) mudah ditekan */
.report-modal-close,#dprModalX,.app-modal-panel button[aria-label^="Tutup"]{min-width:40px;min-height:40px}
/* kolom isian: fokus jelas */
.app-modal-panel :where(input,select,textarea):focus{border-color:#287a4d;box-shadow:0 0 0 3px rgba(40,122,77,.18);outline:none}
/* baris tombol Simpan/Batal menempel di bawah panel saat form panjang digulir */
.app-modal-panel :where(div):has(>button[type=submit]){position:sticky;bottom:0;z-index:6;background:#fff;padding:.75rem 0 calc(.75rem + env(safe-area-inset-bottom));margin-top:.5rem}
#dprSaveBtn{max-width:100%}

@media (max-width:767px){
  /* overlay: lembar dari bawah (bottom-sheet) */
  html .app-modal,html #detailModal,html #fullReportModal,html #dprModal,html #coordWarnModal,html .modal-bg{
    padding:12px !important;align-items:center !important;justify-content:center !important}
  html .app-modal-panel,html #detailModal .app-modal-panel,html #fullReportModal .app-modal-panel,html #dprModal>div,html #coordWarnModal>div{
    width:100% !important;max-width:100% !important;margin:0 !important;
    max-height:calc(100dvh - 24px) !important;overflow-y:auto !important;overflow-x:hidden !important;
    border-radius:16px !important;animation:kkPop .18s ease-out}
  html #coordWarnModal>div{padding:1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom)) !important}
  /* pembungkus tambahan di modal narasi lengkap */
  html #fullReportModal>.flex{min-height:0 !important;width:100%;padding:0 !important;align-items:center !important}
  /* pegangan geser dekoratif */
  /* header modal menempel & ringkas */
  .app-modal-panel>.sticky{padding:.75rem 1rem !important}
  .app-modal-panel h3{font-size:1rem !important;line-height:1.3}
  /* isi form: satu kolom, ruang napas cukup */
  .app-modal-panel form,.app-modal-panel>div.p-5{padding:1rem !important}
  .app-modal-panel .grid{grid-template-columns:minmax(0,1fr) !important;gap:.75rem !important}
  .app-modal-panel .grid>.sm\:col-span-2,.app-modal-panel .grid>.col-span-2{grid-column:auto !important}
  .app-modal-panel label{display:block}
  .app-modal-panel :where(input,select,textarea){width:100%;max-width:100%}
  .app-modal-panel input[type=radio],.app-modal-panel input[type=checkbox]{width:20px;min-height:20px;height:20px}
  .app-modal-panel fieldset label{display:flex;align-items:center;gap:.5rem;min-height:44px}
  /* baris tombol aksi: tombol melebar berdampingan */
  .app-modal-panel :where(div):has(>button[type=submit]){padding-left:1rem;padding-right:1rem;margin-left:-1rem;margin-right:-1rem;border-top:1px solid #e2e8f0;box-shadow:0 -6px 14px -10px rgba(15,23,42,.25)}
  .app-modal-panel :where(div):has(>button[type=submit])>button{flex:1 1 0;min-height:46px}
  /* tabel di dalam modal bisa digeser, bukan memecah layar */
  .app-modal-panel .overflow-x-auto,.app-modal-panel .overflow-auto{max-width:100%}
  /* modal detail DPR: konten tidak dibatasi tinggi ganda */
  html #dprModalC{max-height:none !important;padding:1rem !important}
  #dprModal>div>div:first-child{position:sticky;top:0;z-index:5}
  #dprModal>div>div:last-child{position:sticky;bottom:0;background:#fff;z-index:5;padding-bottom:calc(.75rem + env(safe-area-inset-bottom))}
  #dprModal>div>div:last-child>button{min-height:46px}
  /* toast tidak menutup menu bawah */
  #toast{left:12px !important;right:12px !important;max-width:none !important;text-align:center}
  /* popup Leaflet muat di layar */
  .leaflet-popup-content-wrapper{max-width:84vw}
  .leaflet-popup-content{max-width:78vw !important;width:auto !important;margin:10px 12px !important;font-size:13px}
  .leaflet-popup-content table{display:block;overflow-x:auto;max-width:100%}
  .leaflet-control-container .leaflet-top.leaflet-right{max-width:60vw}
  /* kontrol filter tanggal (flatpickr) */
  .flatpickr-calendar{max-width:96vw !important}
}

/* tema gelap untuk modal */
html.kk-c .app-modal-panel,html.kk-c #dprModal>div,html.kk-c #coordWarnModal>div,html.kk-c .app-modal-panel .sticky,html.kk-c .app-modal-panel :where(div):has(>button[type=submit]){background:#101d17 !important;color:#eef6f1}
html.kk-c .app-modal-panel .border-b,html.kk-c .app-modal-panel .border-t{border-color:#25382e !important}
html.kk-c .app-modal-panel::before{background:#33493d}
html.kk-c .app-modal-panel label{color:#cfe3d6 !important}
html.kk-c #dprModal>div>div:first-child{background:#16271f !important}
html.kk-c .leaflet-popup-content-wrapper,html.kk-c .leaflet-popup-tip{background:#101d17;color:#eef6f1}

/* =====================================================================
   PERBAIKAN TABRAKAN & TEKS KELUAR TOMBOL (v6)
   ===================================================================== */
/* teks tidak boleh keluar dari tombol / pil */
main button:not(.matrix-table button),.app-modal-panel button,#kkThemeBox button{overflow-wrap:anywhere;max-width:100%}
main .rounded-full{max-width:100%;overflow:hidden;text-overflow:ellipsis;vertical-align:middle}
#activeExtinctionRecap>*,#activeExtinctionCount{white-space:nowrap}

@media (max-width:767px){
  /* tombol Tampilan: hanya ikon, apa pun versi JS-nya */
  #kkThemeBox>button:last-child{font-size:0 !important;line-height:0;width:44px;height:44px;padding:0 !important;display:flex !important;align-items:center;justify-content:center;border-radius:50%}
  #kkThemeBox>button:last-child::before{content:"🎨";font-size:20px;line-height:1}
  #kkThemeBox{right:10px;bottom:calc(76px + env(safe-area-inset-bottom)) !important}

  /* kepala kartu (judul + pil + tombol): tersusun ke bawah, tidak berdesakan */
  main .mb-4.flex.items-center.justify-between,main .mb-4.flex.items-start.justify-between{flex-direction:column;align-items:stretch !important;gap:.75rem}
  main .mb-4.flex.justify-between>.flex.flex-wrap{justify-content:flex-start !important;width:100%}
  main .mb-4.flex.justify-between>.flex.flex-wrap>span.flex{flex-wrap:wrap}
  main .mb-4.flex.justify-between>.flex.flex-wrap button[data-export]{min-height:36px;padding:.4rem .9rem;white-space:nowrap}

  /* toolbar Matriks: pencarian & tombol tidak saling menimpa */
  #kawasanSearchFilter{min-width:0;width:100%}
  #kawasanSearchFilter:focus{box-shadow:0 0 0 3px rgba(40,122,77,.18)}
  #pulauFilter{flex:1 1 100%;width:100%}
  html #kawasanSearchFilter{height:44px}
  div:has(>#kawasanSearchFilter){flex:1 1 100% !important;min-width:0 !important;width:100%}
  html #addReportBtn{flex:1 1 100%;min-height:46px;text-align:center}
  html #expandAll,html #collapseAll{flex:1 1 calc(50% - .25rem);min-height:44px;text-align:center}
  .matrix-period-panel .flex.flex-wrap>button{flex:1 1 calc(50% - .25rem);min-height:44px;text-align:center;white-space:normal}

  /* tabel dalam kartu: kolom tidak terjepit; teks tanggal tidak terpotong */
  main :where(.overflow-auto,.overflow-x-auto)>table:not(.matrix-table){min-width:640px}
  main :where(.overflow-auto,.overflow-x-auto)>table:not(.matrix-table) :where(td,th){padding:.55rem .65rem !important;vertical-align:top}
  main :where(.overflow-auto,.overflow-x-auto)>table:not(.matrix-table) td:last-child{white-space:nowrap}
}

/* =====================================================================
   v7 - Anti-melebar: dropdown Tom Select, select/input panjang, halaman tak boleh geser
   ===================================================================== */
body{overflow-x:clip}
.ts-wrapper{width:100% !important;max-width:100%;min-width:0}
.ts-control{max-width:100%;min-width:0;overflow:hidden}
.ts-control>.item,.ts-wrapper.single .ts-control>.item{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ts-dropdown{max-width:calc(100vw - 24px)}
.ts-dropdown .option{white-space:normal;overflow-wrap:anywhere}
label{min-width:0}
label>select,label>input:not([type=checkbox]):not([type=radio]),label>.ts-wrapper{max-width:100%}
select{max-width:100%;text-overflow:ellipsis}
.leaflet-container{max-width:100%}
@media (max-width:767px){
  html,body{width:100%}
  #view-hotspot section>.grid.gap-4{grid-template-columns:minmax(0,1fr)}
  #view-hotspot .grid>*,#view-hotspot label,#view-hotspot fieldset{min-width:0;max-width:100%}
  #hsRange,#hsUpt,#hsProv{width:100%;min-width:0}
  #view-hotspot [data-hs-quick]{flex:1 1 auto;white-space:nowrap}
  #view-hotspot :where(#hsFetch,#hsReset,#hsExpShp,#hsExpXlsx,#hsCancel){flex:1 1 calc(50% - .25rem);min-height:44px;text-align:center}
  #view-hotspot #hsFetch{flex-basis:100%}
  #hsTopMode{width:100%}
  #hsTopMode>button{flex:1 1 0}
  :is(.view,main) .grid{max-width:100%}
}

/* v8 - kunci lebar halaman: konten yang melebar dipotong, tidak memperlebar layar */
@media (max-width:767px){
  html{overflow-x:hidden !important;max-width:100%}
  body,header.sticky,main,main .view{overflow-x:clip}
  main .view{max-width:100%}
  main .view>section,main .view>article,main .view>div{max-width:100%;min-width:0}
}

/* v9 - isi tombol di dalam tabel (mis. kolom Total SDM) tidak boleh dipatah per huruf */
html main table button,html main table td,html main table th{overflow-wrap:normal !important;word-break:normal !important}
html main table button{white-space:normal;text-align:inherit;max-width:none !important}
#view-dpr-detail table th:nth-child(2),#view-dpr-detail table td:nth-child(2){min-width:230px}
#view-dpr-detail table th:nth-child(3),#view-dpr-detail table td:nth-child(3){min-width:130px}
@media (max-width:767px){
  #view-dpr-detail table{min-width:820px}
  html.kk-c .app-modal-panel::before{display:none}
}
