/* ============================================================
   qgis2web custom theme — dark sidebar, clean & minimal
   ============================================================ */

:root {
    --bg: #0b1120;
    --panel: #111a2e;
    --panel-2: #182238;
    --panel-3: #1f2b45;
    --border: #243150;
    --text: #e2e8f0;
    --muted: #8fa3c8;
    --accent: #38bdf8;
    --accent-2: #818cf8;
    --danger: #f87171;
    --radius: 12px;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --sidebar-w: 330px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    overflow: hidden;
}

#app { display: flex; height: 100vh; width: 100vw; }

/* ============ Sidebar ============ */
#sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--panel) 0%, #0e1630 100%);
    border-right: 1px solid var(--border);
    z-index: 1200;
}

.sidebar-header {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }

.brand-logo {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    object-fit: contain;
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 3px;
}

.brand-text { min-width: 0; flex: 1; }

.brand-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    margin: 2px 0 0;
    font-size: 11.5px;
    color: var(--muted);
}

.kkn-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.14), rgba(129, 140, 248, 0.14));
    border: 1px solid rgba(56, 189, 248, 0.35);
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.2px;
    flex-wrap: wrap;
}

.kkn-badge-logo {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    border: 1px solid rgba(56, 189, 248, 0.45);
    padding: 2px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s ease, transform 0.15s ease;
}

.icon-btn:hover { background: var(--panel-3); transform: translateY(-1px); }

/* ============ Search ============ */
.search-box {
    position: relative;
    padding: 14px 16px 12px;
}

.search-box-icon {
    position: absolute;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 13px;
    pointer-events: none;
}

#search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

#search-input::placeholder { color: var(--muted); }

#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.search-results {
    position: absolute;
    left: 16px;
    right: 16px;
    top: calc(100% - 6px);
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 1300;
}

.search-results.open { display: block; }

.search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.search-item:hover { background: var(--panel-3); }

.search-item .s-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.search-item .s-name {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-item .s-type {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.search-empty {
    padding: 10px;
    text-align: center;
    color: var(--muted);
    font-size: 12.5px;
}

/* ============ Sidebar body ============ */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 4px 16px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.side-section { margin-top: 14px; }

.side-title {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.side-title i { color: var(--accent); font-size: 12px; }

/* ============ Layer list ============ */
.layer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
    user-select: none;
}

.layer-item:hover { background: var(--panel-2); }

.layer-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    border: 2px solid #3b4c74;
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.layer-item input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.layer-item input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: solid #08131f;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.layer-item .l-swatch {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    border-radius: 5px;
}

.layer-item .l-name {
    font-size: 13px;
    line-height: 1.3;
}

/* ============ Legend ============ */
.legend-group { margin-bottom: 16px; }

.legend-group-title {
    margin: 0 0 7px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
    font-size: 12.5px;
}

.legend-item .lg-dot {
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    border-radius: 50%;
}

.legend-item .lg-line {
    width: 22px;
    height: 5px;
    flex: 0 0 22px;
    border-radius: 3px;
}

.legend-item .lg-box {
    width: 15px;
    height: 13px;
    flex: 0 0 15px;
    border-radius: 3px;
}

/* ============ Sidebar footer ============ */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 10.5px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    line-height: 1.5;
}

/* ============ Map ============ */
#map-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg);
}

.menu-toggle {
    display: none;
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 18, 0.6);
    z-index: 1150;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

/* ============ OL controls (dark) ============ */
.ol-control {
    background: transparent !important;
    box-shadow: none !important;
}

.ol-control button {
    background-color: var(--panel) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    margin: 2px !important;
    width: 40px !important;
    height: 40px !important;
    font-size: 1.25em !important;
    line-height: 0.6 !important;
    transition: background 0.15s ease;
}

.ol-control button:hover {
    background-color: var(--panel-3) !important;
}

/* zoom control lives inside #top-left-container (left:0 top:0 of the
   map viewport, which sits right of the sidebar on desktop) */
.ol-zoom .ol-zoom-in { border-radius: 10px 10px 4px 4px !important; }
.ol-zoom .ol-zoom-out { border-radius: 4px 4px 10px 10px !important; }

/* attribution */
.bottom-attribution {
    background: rgba(13, 20, 38, 0.85) !important;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px 12px;
    font-size: 11px;
    color: var(--muted);
    backdrop-filter: blur(6px);
}

.bottom-attribution a { color: var(--accent) !important; }

/* ============ Popup ============ */
/* NOTE: OL writes inline left/top on #popup via overlayPopup.setPosition() —
   never override them with !important. `bottom:auto`/`left:auto` here are
   plain author rules that only neutralize qgis2web.css (inline styles win).
   The transform centers the card horizontally and parks it above the point,
   with the :after arrow at top:100% pointing down at the click coordinate. */
.ol-popup {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px 14px;
    box-shadow: var(--shadow);
    min-width: 220px;
    max-width: 320px;
    bottom: auto;
    left: auto;
    transform: translate(-50%, -100%);
}

.ol-popup:after {
    top: 100% !important;
    left: 50%;
    margin-left: -8px;
    border: 8px solid transparent;
    border-top-color: var(--panel);
    border-width: 8px !important;
}

.ol-popup:before { display: none; }

.ol-popup-closer {
    color: var(--muted) !important;
    font-family: inherit;
    font-size: 14px;
    top: 8px;
    right: 10px;
    width: 26px;
    height: 26px;
    line-height: 26px;
    border-radius: 8px;
    text-align: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.ol-popup-closer:hover { background: var(--panel-3); color: var(--text) !important; }

.ol-popup-closer:after { content: "\00d7"; font-size: 16px; font-weight: 600; }

#popup-content {
    font-size: 13px;
    line-height: 1.55;
    margin-top: 0;
    max-height: 55vh;
    max-width: 300px;
    overflow: auto;
    color: var(--text);
}

#popup-content ul { list-style: none; margin: 0; padding: 0; }
#popup-content li { margin: 0; }
#popup-content table { border-collapse: collapse; width: 100%; font-size: 13px; }

/* popup text must stay light on the dark card — neutralise qgis2web.css
   `th, td { color: #333 }` and the 100px min-width squeeze */
#popup-content table td,
#popup-content table th {
    color: var(--text);
    min-width: 0;
}
#popup-content table td.pp-label {
    color: var(--muted);
    min-width: 96px;
}

/* field-level links (e.g. Autolinker URLs in Keterangan) stay on-theme
   instead of the browser's default low-contrast blue */
#popup-content table td a {
    color: var(--accent);
    text-decoration: none;
}
#popup-content table td a:hover { text-decoration: underline; }

/* the popup title <a> is fostered OUT of the table by the HTML parser
   (an <a> is invalid inside <table>) — it lands as a direct child of the
   <li>, so target it via the ul > li path (same specificity as
   qgis2web.css's #popup-content>ul>li>a; custom.css loads after) */
#popup-content > ul > li > a {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--accent);
    padding-bottom: 7px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.pp-row td { padding: 4px 0; border: none; vertical-align: top; }

/* subtle divider between rows for a calmer read */
.pp-row + .pp-row td {
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    padding-top: 8px;
}

#popup-content table tr.pp-name td {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    padding-bottom: 5px;
    line-height: 1.35;
}
.pp-amenity td, .pp-road td { padding: 5px 0 7px; }

.pp-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    color: #fff;
    background: var(--ppc); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--ppc) 82%, #0b1120);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.pp-badge i { font-size: 11px; }

.pp-road-badge {
    background: transparent;
    box-shadow: none;
    color: var(--text);
    padding: 3px 0;
    font-weight: 600;
}

.pp-line {
    width: 20px;
    height: 5px;
    border-radius: 3px;
    display: inline-block;
}

.pp-label {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.2px;
    padding-right: 14px;
    text-transform: capitalize;
}

/* ============ Responsive ============ */
@media (max-width: 820px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(var(--sidebar-w), 86vw);
        transform: translateX(-105%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow);
    }

    body.sidebar-open #sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; pointer-events: auto; }

    .menu-toggle { display: flex; align-items: center; justify-content: center; }

    /* move zoom stack to the top-right, clear of the menu toggle */
    #top-left-container { left: auto; right: 12px; top: 12px; bottom: auto; }
    #top-left-container .ol-zoom { margin: 0; }
}

@media (max-width: 480px) {
    .ol-popup { min-width: 190px; max-width: 260px; }
    #popup-content { max-width: 240px; }
}

@media (max-width: 380px) {
    .brand-logo { width: 34px; height: 34px; flex-basis: 34px; }
    .brand { gap: 8px; }
    .icon-btn { width: 34px; height: 34px; flex-basis: 34px; }
    .brand-title { font-size: 14px; }
    .kkn-badge { font-size: 10px; padding: 6px 9px; }
}
