/* ==========================================================================
   Responsive overrides for qgis2web export (mobile / tablet / desktop)
   Loaded AFTER qgis2web.css and ol-layerswitcher.css
   ========================================================================== */

/* ---------- Page / map sizing ---------- */
html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
#map {
    height: 100%;
    height: 100dvh;           /* real visible height on mobile browsers (URL bar) */
    touch-action: none;
}

/* keep controls clear of notches / rounded corners / home indicator */
#top-left-container {
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
}
#bottom-left-container {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
}
#bottom-right-container {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    max-width: 100vw;
    box-sizing: border-box;
}

.ol-control button,
.layer-switcher button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Layer switcher ---------- */
/* wrapper: fixed to the top-right corner, button on top, panel below it */
.ol-control.layer-switcher,
.ol-control.layer-switcher.shown {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    left: auto;
    bottom: auto;
    float: none;
    margin: 0;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    max-width: calc(100vw - 16px);
    max-height: none;
    overflow: visible;
    background: transparent !important;
    box-shadow: none;
    box-sizing: border-box;
    z-index: 5;
}
.ol-control.layer-switcher:hover,
.ol-control.layer-switcher.shown:hover {
    background: transparent !important;
}

/* open / close button (always visible) */
.ol-control.layer-switcher > button,
.ol-control.layer-switcher.shown > button {
    display: block;
    position: relative;
    float: none;
    left: auto;
    right: auto;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background-color: #f8f8f8;
    background-repeat: no-repeat;
    background-position: center;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
    cursor: pointer;
}
/* when opened the same button becomes a big "×" */
.ol-control.layer-switcher.shown > button {
    background-image: none;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 30px;
    font-weight: 400;
    line-height: 42px;
    text-align: center;
    color: #444;
}

/* keep panel/button opaque (index.html makes hovered controls 70% transparent,
   and touch screens keep the :hover state after a tap) */
.ol-control.layer-switcher > .panel,
.ol-control.layer-switcher > .panel:hover,
.ol-control.layer-switcher > .panel:focus {
    background-color: #f8f8f8 !important;
}
.ol-control.layer-switcher > button:hover,
.ol-control.layer-switcher > button:focus {
    background-color: #f8f8f8 !important;
}

/* the panel with the layer list */
.ol-control.layer-switcher .panel {
    display: none;
    position: static;
    float: none;
    width: max-content;
    min-width: 220px;
    max-width: calc(100vw - 16px);
    max-width: min(380px, calc(100vw - 16px));
    height: auto;
    max-height: calc(100vh - 76px);
    max-height: calc(100dvh - 76px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    margin: 0;
    border: 0;
    border-radius: 8px;
    box-sizing: border-box;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}
.ol-control.layer-switcher.shown .panel {
    display: block;
}

.layer-switcher .panel > ul {
    margin: 4px;
    padding: 0;
    list-style: none;
}

/* one row per layer: big checkbox on the left, tappable label */
.layer-switcher li.layer {
    position: relative;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.layer-switcher li.layer:last-child {
    border-bottom: 0;
}
.layer-switcher li.layer > label {
    display: block;
    margin: 0;
    padding: 10px 12px 10px 42px;
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.layer-switcher li.layer.has-legend > label {
    padding-right: 46px;
}
.layer-switcher li.layer > input {
    position: absolute;
    left: 11px;
    top: 10px;
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
}

/* legend rows (image + wrapped text) */
.layer-switcher .legend-body {
    margin-top: 6px;
}
.layer-switcher .legend-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin: 2px 0;
}
.layer-switcher .legend-row img {
    flex: 0 0 auto;
    max-width: 22px;
    max-height: 22px;
}
.layer-switcher .legend-row span {
    min-width: 0;
    padding-top: 2px;
}
.layer-switcher li.legend-collapsed .legend-body {
    display: none;
}

/* legend show/hide button */
.layer-switcher .legend-toggle,
.layer-switcher.shown .legend-toggle {
    display: block;
    position: absolute;
    top: 3px;
    right: 4px;
    float: none;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background-image: none !important;
    background-color: transparent !important;
    cursor: pointer;
}
.layer-switcher .legend-toggle:hover,
.layer-switcher .legend-toggle:focus-visible {
    background-color: rgba(0, 0, 0, 0.07) !important;
}
.layer-switcher .legend-toggle::before {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    margin: 12px auto 0;
    border-right: 2px solid #555;
    border-bottom: 2px solid #555;
    transform: rotate(225deg);          /* chevron up = legend visible */
    transition: transform 0.2s ease;
}
.layer-switcher li.legend-collapsed .legend-toggle::before {
    margin-top: 10px;
    transform: rotate(45deg);           /* chevron down = legend hidden */
}

/* ---------- Popup ---------- */
.ol-popup-closer {
    width: 28px;
    height: 28px;
    line-height: 28px;
    top: 2px;
    right: 2px;
    font-size: 15px;
    z-index: 1;
}
.ol-popup {
    width: max-content;
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
}
#popup-content {
    max-height: 60vh;
    max-height: 60dvh;
    max-width: calc(100vw - 64px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
#popup-content a,
#popup-content b,
#popup-content td,
#popup-content th {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ---------- Attribution ---------- */
.bottom-attribution {
    max-width: 100vw;
    box-sizing: border-box;
}
.bottom-attribution ul {
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ---------- Phones / small screens ---------- */
@media (max-width: 650px) {
    .ol-control.layer-switcher .panel {
        min-width: 0;
    }
    .layer-switcher li.layer > label {
        font-size: 14px;
    }
    .layer-switcher li.layer > input {
        top: 11px;
    }
    .ol-popup {
        padding: 12px;
        max-width: calc(100vw - 24px);
    }
    #popup-content {
        max-width: calc(100vw - 72px);
        max-height: 50vh;
        max-height: 50dvh;
    }
    th, td {
        min-width: 0;
    }
    .bottom-attribution {
        font-size: 11px;
    }
}

/* very narrow phones: panel spans the full width like a sheet */
@media (max-width: 480px) {
    .ol-control.layer-switcher .panel {
        width: calc(100vw - 16px);
    }
}

/* touch devices: larger tap targets */
@media (pointer: coarse) {
    .layer-switcher li.layer > input {
        width: 22px;
        height: 22px;
        left: 10px;
    }
    .layer-switcher li.layer > label {
        padding-left: 44px;
        padding-top: 12px;
    }
}

/* phones in landscape (short screens) */
@media (max-height: 520px) {
    .ol-control.layer-switcher .panel {
        max-height: calc(100vh - 68px);
        max-height: calc(100dvh - 68px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
    #popup-content {
        max-height: 45vh;
        max-height: 45dvh;
    }
}
/* ======================================================================
   FIX: tombol legenda / tombol lipat grup tertindih checkbox
   Penyebab: aturan ".layer-switcher .group button" (ol-layerswitcher.css)
   punya specificity lebih tinggi dari ".layer-switcher .legend-toggle",
   sehingga left:0, ikon panah & rotasi grup ikut menempel ke tombol
   legenda dan menutupi checkbox di sisi kiri.
   ====================================================================== */

/* 1. Tombol legenda: paksa di sisi kanan, tanpa left/rotate bawaan grup */
.layer-switcher .group .legend-toggle,
.layer-switcher.shown .group .legend-toggle {
    left: auto !important;
    right: 4px !important;
    top: 3px !important;
    width: 40px !important;
    height: 40px !important;
    transform: none !important;
    -webkit-transform: none !important;
    transition: background-color 0.15s ease;
    background-image: none !important;
    z-index: 2;
}
.layer-switcher .legend-toggle {
    left: auto;
    transform: none;
}

/* 2. Baris grup: [panah lipat] [checkbox] [judul grup] tersusun rapi */
.layer-switcher li.group {
    position: relative;
    margin: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.layer-switcher li.group:last-child {
    border-bottom: 0;
}
.layer-switcher li.group > label {
    display: block;
    margin: 0;
    padding: 10px 12px 10px 62px;
    font-size: 13px;
    font-weight: bold;
    line-height: 1.35;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.layer-switcher li.group > input {
    position: absolute;
    left: 36px;
    top: 10px;
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
}
/* tombol lipat/buka grup (panah) di paling kiri, area sentuh lebih besar */
.layer-switcher li.group > button {
    position: absolute;
    left: 4px;
    top: 4px;
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    float: none;
    border: 0;
    border-radius: 6px;
    background-color: transparent !important;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    z-index: 2;
}
.layer-switcher li.group > button:hover,
.layer-switcher li.group > button:focus-visible {
    background-color: rgba(0, 0, 0, 0.07) !important;
}
/* grup tanpa panah lipat: checkbox geser ke kiri */
.layer-switcher li.group:not(.layer-switcher-fold) > input {
    left: 12px;
}
.layer-switcher li.group:not(.layer-switcher-fold) > label {
    padding-left: 40px;
}

/* 3. Isi grup: sedikit menjorok ke kanan sebagai penanda hirarki */
.layer-switcher li.group > ul {
    margin: 0;
    padding: 0 0 0 14px;
    border-left: 2px solid rgba(0, 0, 0, 0.08);
    margin-left: 14px;
}

/* 4. Layar sentuh: ukuran checkbox grup ikut membesar */
@media (pointer: coarse) {
    .layer-switcher li.group > input {
        width: 22px;
        height: 22px;
    }
}
