/* Karte (/map): vadīklu izkārtojums un izskats.

   Kāpēc šis fails: kreisajā augšējā stūrī vienā kolonnā bija visas vadīklas, arī ~13 Geoman zīmēšanas
   pogas. Kolonna bija augstāka par karti jau pie ~730 px augsta loga (1920×1080, Windows mērogs 125%),
   un apakšējās pogas un mēroga izvēle bija nogrieztas — Leaflet vadīklas neritinās un netiek pārnestas.
   Tagad zīmēšanas rīki ir aiz vienas pogas "Zīmēt" un atveras kā horizontāla josla blakus tai
   (leaflet-map.js Draw.addControl). Izkārtojums ir vienāds visos ekrānos, nav atkarīgs no augstuma.

   Viss ir zem .mapContainer, lai neskartu maršruta karti (routeMap.js), kurai ir savas vadīklas. */

/* --- Pogu bloki: mīkstāka ēna un noapaļoti stūri visām vadīklām vienādi --- */
.mapContainer .leaflet-bar,
.mapContainer .leaflet-control-layers,
.mapContainer .leaflet-searchbox-container {
    border: none;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.08);
}

.mapContainer .leaflet-bar a {
    transition: background-color 0.12s ease-in-out;
}

    .mapContainer .leaflet-bar a:first-child {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
    }

    .mapContainer .leaflet-bar a:last-child {
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
    }

    .mapContainer .leaflet-bar a:hover {
        background-color: #eef5ec;
    }

/* --- Poga "Zīmēt" --- */
.leaflet-pm-draw-toggle a {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 18px 18px;
}

.leaflet-container.pm-draw-open .leaflet-pm-draw-toggle a {
    background-color: #2e7d32;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
}

/* --- Geoman josla: horizontāla, blakus pogai "Zīmēt", redzama tikai atvērtā stāvoklī ---
   Pozīciju (--pm-toolbar-top/left) uzliek JS, jo Geoman, mainot valodu (setLang), joslu izveido no jauna
   un iekļautie stili pazustu; CSS mainīgie uz kartes konteinera paliek. Absolūta pozīcija nozīmē, ka josla
   neaizņem vietu kolonnā, un aizvērta (display: none) tā nebloķē kartes vilkšanu. */
.mapContainer .leaflet-pm-toolbar {
    display: none;
}

.mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar {
    position: absolute;
    top: var(--pm-toolbar-top, 0);
    left: var(--pm-toolbar-left, 50px);
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    /* Stūra konteiners ir tikai kolonnas platumā — bez šī josla sašaurinātos līdz vienai pogai. */
    width: max-content;
    max-width: calc(var(--map-w, 100vw) - var(--pm-toolbar-left, 50px) - 20px);
    background: #fff;
}

    .mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar .button-container {
        position: relative;
    }

        .mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar .button-container a.leaflet-buttons-control-button {
            border-bottom: none;
            border-right: 1px solid #e3e3e3;
            border-radius: 0;
        }

        .mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar .button-container:first-child a.leaflet-buttons-control-button {
            border-top-left-radius: 8px;
            border-bottom-left-radius: 8px;
        }

        .mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar .button-container:last-child a.leaflet-buttons-control-button {
            border-right: none;
            border-top-right-radius: 8px;
            border-bottom-right-radius: 8px;
        }

        /* Rīka darbības ("Pabeigt", "Atcelt", "Noņemt pēdējo virsotni") — zem pogas, nevis pa labi,
           kur tās aizsegtu nākamās joslas pogas. */
        .mapContainer .leaflet-container.pm-draw-open .leaflet-pm-toolbar .button-container .leaflet-pm-actions-container {
            top: 100%;
            left: 0;
            margin-top: 4px;
            z-index: 1;
        }

/* --- Slāņu panelis: augstums pēc KARTES augstuma (--map-h uzliek leaflet-layer-tree-control.js), nevis pēc
   loga, un ar atstarpi apakšā tērzēšanas pogai — citādi pēdējais slānis palika zem tās. --- */
.mapContainer .leaflet-layer-tree-control-layers-open,
.mapContainer .leaflet-layer-tree-control-order-open {
    max-height: calc(var(--map-h, 100vh) - 120px);
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 8px;
}

/* =====================================================================================================
   Kartes rīki (js/mapTools.js): meklēšana, punkts, mērīšana, fona kartes, izvēlne, pilnekrāns.
   Krāsa — lietotnes zaļā (#2e7d32). Visi uznirstošie paneļi ir absolūti un aizvērti display: none,
   lai neaizņemtu kartes vietu (Leaflet vadīkla pieķer klikšķus visā savā kastē).
   ===================================================================================================== */

.fm-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

    .fm-btn svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: #333;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .fm-btn.fm-btn-on {
        background-color: #2e7d32 !important;
    }

        .fm-btn.fm-btn-on svg {
            stroke: #fff;
        }

.leaflet-container.fm-crosshair,
.leaflet-container.fm-crosshair .leaflet-interactive {
    cursor: crosshair !important;
}

/* --- Norāde aktīvam rīkam (augšā vidū) --- */
.fm-hint {
    display: none;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: calc(100% - 120px);
    align-items: center;
    gap: 10px;
    padding: 6px 8px 6px 14px;
    background: rgba(33, 33, 33, 0.88);
    color: #fff;
    border-radius: 20px;
    font-size: 13px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

    .fm-hint.fm-hint-on {
        display: flex;
    }

.fm-hint-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fm-hint-actions {
    display: flex;
    gap: 6px;
}

.fm-hint-btn {
    border: 0;
    border-radius: 14px;
    padding: 3px 12px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
}

    .fm-hint-btn:hover {
        background: rgba(255, 255, 255, 0.28);
    }

.fm-hint-btn-primary {
    background: #43a047;
}

    .fm-hint-btn-primary:hover {
        background: #2e7d32;
    }

/* --- Meklēšana --- */
.fm-search {
    position: relative;
}

.fm-search-panel {
    display: none;
    position: absolute;
    top: 0;
    left: calc(100% + 6px);
    width: 340px;
    max-width: calc(100vw - 90px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.fm-search.fm-search-open .fm-search-panel {
    display: block;
}

.fm-search-input {
    width: 100%;
    height: 34px;
    border: 0;
    outline: none;
    padding: 0 12px;
    font-size: 14px;
}

.fm-search-results {
    max-height: 340px;
    overflow-y: auto;
    border-top: 1px solid #eee;
}

    .fm-search-results:empty {
        display: none;
    }

.fm-search-group {
    padding: 8px 12px 2px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
}

.fm-search-item {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 6px 12px;
    cursor: pointer;
}

    .fm-search-item:hover,
    .fm-search-item.fm-search-item-on {
        background: #eef5ec;
    }

.fm-search-main {
    display: block;
    font-size: 14px;
    color: #222;
}

.fm-search-sub {
    display: block;
    font-size: 12px;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fm-search-message {
    padding: 10px 12px;
    font-size: 13px;
    color: #777;
}

/* --- Mērīšanas izvēle (Attālums / Laukums) --- */
.fm-measure {
    position: relative;
}

.fm-flyout {
    display: none;
    position: absolute;
    top: 0;
    left: calc(100% + 6px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 4px;
    white-space: nowrap;
}

.fm-measure.fm-flyout-open .fm-flyout {
    display: flex;
    gap: 2px;
}

.fm-menu-item {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 13px;
}

    .fm-menu-item svg {
        width: 16px;
        height: 16px;
        fill: none;
        stroke: #333;
        stroke-width: 2;
        stroke-linejoin: round;
    }

    .fm-menu-item:hover,
    .fm-menu-item.fm-menu-on {
        background: #eef5ec;
    }

.fm-measure-shape {
    stroke: #e65100;
    stroke-width: 3;
    stroke-dasharray: 6 5;
    fill: #ff9800;
    fill-opacity: 0.15;
}

.fm-measure-vertex {
    stroke: #e65100;
    stroke-width: 2;
    fill: #fff;
    fill-opacity: 1;
}

.fm-measure-label.leaflet-tooltip {
    background: #e65100;
    color: #fff;
    border: 0;
    border-radius: 12px;
    padding: 2px 10px;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

    .fm-measure-label.leaflet-tooltip::before {
        display: none;
    }

.fm-measure-result {
    background: transparent;
    border: 0;
    white-space: nowrap;
}

    .fm-measure-result > span {
        display: inline-block;
        background: #e65100;
        color: #fff;
        border-radius: 12px 0 0 12px;
        padding: 2px 6px 2px 10px;
        font-weight: 600;
        font-size: 12px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
        vertical-align: middle;
    }

    .fm-measure-result > button {
        display: inline-flex;
        align-items: center;
        border: 0;
        background: #bf360c;
        border-radius: 0 12px 12px 0;
        padding: 4px 6px;
        vertical-align: middle;
    }

        .fm-measure-result > button svg {
            width: 12px;
            height: 12px;
            fill: none;
            stroke: #fff;
            stroke-width: 3;
        }

/* --- Punkts --- */
.fm-pin {
    background: transparent;
    border: 0;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

    .fm-pin svg path {
        fill: #2e7d32;
        stroke: #fff;
        stroke-width: 1.5;
    }

.fm-popup .leaflet-popup-content {
    margin: 10px 12px;
}

.fm-pop-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.fm-pop-label {
    width: 48px;
    font-size: 11px;
    font-weight: 600;
    color: #888;
}

.fm-pop-value {
    flex: 1;
    font-family: Consolas, monospace;
    font-size: 12px;
}

.fm-pop-copy {
    border: 0;
    background: transparent;
    padding: 2px;
    border-radius: 4px;
    line-height: 0;
}

    .fm-pop-copy svg {
        width: 15px;
        height: 15px;
        fill: none;
        stroke: #555;
        stroke-width: 2;
    }

    .fm-pop-copy:hover {
        background: #eef5ec;
    }

    .fm-pop-copy.fm-pop-copied svg {
        stroke: #2e7d32;
    }

.fm-pop-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #eee;
}

.fm-pop-link {
    color: #2e7d32 !important;
    font-weight: 600;
}

.fm-pop-remove {
    border: 0;
    background: transparent;
    color: #c62828;
    font-size: 12px;
}

/* --- Fona kartes (apakšā kreisajā stūrī, virs mēroga) --- */
.mapContainer .leaflet-bottom.leaflet-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.fm-base {
    order: -1;
    position: relative;
}

.fm-base-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    padding: 6px 10px;
    font-size: 13px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.08);
}

    .fm-base-btn svg {
        width: 18px;
        height: 18px;
        fill: #2e7d32;
        stroke: none;
    }

.fm-base-name {
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fm-base-panel {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    max-height: calc(var(--map-h, 100vh) - 140px);
    overflow-y: auto;
    padding: 8px;
    gap: 8px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.12);
}

.fm-base.fm-base-open .fm-base-panel {
    display: grid;
    grid-template-columns: repeat(4, 92px);
}

@media (max-width: 600px) {
    .fm-base.fm-base-open .fm-base-panel {
        grid-template-columns: repeat(2, 92px);
    }
}

.fm-base-section {
    grid-column: 1 / -1;
    padding: 2px 2px 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #888;
}

/* Pārklājums ieslēgts — zaļš ķeksītis stūrī (fona kartei pietiek ar rāmi). */
.fm-base-card-overlay {
    position: relative;
}

    .fm-base-card-overlay.fm-base-card-on::after {
        content: "";
        position: absolute;
        top: 4px;
        right: 4px;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: #2e7d32 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center / 12px no-repeat;
    }

.fm-base-card {
    /* Kāds globālais pogu stils dod display: flex rindā — bez šī nosaukums stājās blakus attēlam. */
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    border: 2px solid transparent;
    border-radius: 8px;
    background: transparent;
    padding: 0;
    text-align: center;
    overflow: hidden;
}

    .fm-base-card:hover {
        border-color: #a5d6a7;
    }

    .fm-base-card.fm-base-card-on {
        border-color: #2e7d32;
    }

.fm-base-thumb {
    flex: none;
    width: 88px;
    height: 62px;
    border-radius: 6px 6px 0 0;
    background: #e8eee6;
    pointer-events: none;
}

.fm-base-label {
    display: block;
    padding: 3px 2px;
    font-size: 11px;
    line-height: 1.2;
    height: 30px;
    overflow: hidden;
}

/* --- Labā klikšķa izvēlne --- */
.fm-context {
    display: none;
    position: absolute;
    z-index: 1001;
    min-width: 240px;
    padding: 4px 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.14);
}

    .fm-context.fm-context-on {
        display: block;
    }

.fm-context-head {
    padding: 6px 12px 8px;
    border-bottom: 1px solid #eee;
    cursor: copy;
}

.fm-context-coord {
    display: block;
    font-family: Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
}

.fm-context-sub {
    display: block;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: #888;
}

.fm-context-item {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 6px 12px;
    font-size: 13px;
}

    .fm-context-item:hover {
        background: #eef5ec;
    }

.fm-context-sep {
    height: 1px;
    margin: 4px 0;
    background: #eee;
}

/* --- Slāņu panelis: meklēšana un modernāks izskats --- */
.fm-layer-search {
    position: sticky;
    top: -3px;
    z-index: 1;
    margin: -3px -9px 6px;
    padding: 8px 9px 6px;
    background: #fff;
    border-bottom: 1px solid #eee;
}

    .fm-layer-search input {
        width: 100%;
        height: 30px;
        border: 1px solid #d8dfd6;
        border-radius: 15px;
        padding: 0 12px;
        font-size: 13px;
        outline: none;
    }

        .fm-layer-search input:focus {
            border-color: #43a047;
        }

/* Paneļa aizvēršana blakus meklēšanai (šaurā ekrānā panelis aizsedz savu atvēršanas ikonu). */
.fm-layer-search {
    display: flex;
    align-items: center;
    gap: 6px;
}

    .fm-layer-search input {
        flex: 1;
        min-width: 0;
    }

.fm-layer-close {
    flex: none;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #555;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

    .fm-layer-close:hover {
        background: #eef3ee;
        color: #222;
    }

.fm-layer-hidden {
    display: none !important;
}

.fm-layer-filtering .leaflet-layer-tree-control-leaf-content {
    display: block !important;
}

.mapContainer .leaflet-layer-tree-control-leaf-header {
    border-radius: 6px;
    padding: 1px 4px;
}

    .mapContainer .leaflet-layer-tree-control-leaf-header:hover {
        background: #f3f7f2;
    }

.mapContainer .leaflet-layer-tree-control-leaf-title input[type=range] {
    width: 110px;
    accent-color: #2e7d32;
}

/* Paneļa pogas (atvērt/aizvērt, secība) — baltas, kā pārējās vadīklas. */
.mapContainer .leaflet-layer-tree-control-toggle-open,
.mapContainer .leaflet-layer-tree-control-toggle-closed,
.mapContainer .leaflet-layer-tree-control-order-toggle-open,
.mapContainer .leaflet-layer-tree-control-order-toggle-closed {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.08);
}

/* --- Pilnekrāns: lietotnes josla un sānu izvēlne paslēpta, karte pa visu logu. Dialogi (z-index 1000+)
   paliek virs kartes. --- */
body.map-fullscreen .mud-appbar,
body.map-fullscreen .mud-drawer,
body.map-fullscreen .mud-drawer-overlay {
    display: none !important;
}

body.map-fullscreen .mapContainer {
    position: fixed;
    inset: 0;
    z-index: 900;
    height: auto;
}
