/* Trafikpåverkande lager — grävtillstånd, TA-planer, markupplåtelser.
   Lagerpanel (tänd/släckbara lager) + objekt-popup. Återanvänder tokens från cykelrutt.css. */

/* ---- Lagerpanel ---- */
#cyLayersPanel {
    position: fixed;
    top: calc(var(--edge) + var(--pill-h) + 10px);
    right: var(--edge);
    width: 286px;
    max-width: calc(100vw - 2*var(--edge));
    max-height: calc(100vh - var(--pill-h) - 3*var(--edge));
    max-height: calc(100dvh - var(--pill-h) - 3*var(--edge));
    overflow-y: auto;
    z-index: 4700;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 14px 16px 16px;
    animation: cy-drop-in .16s var(--ease);
}
.cy-layers-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 10px;
}
.cy-layer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
}
.cy-layer-swatch {
    flex: 0 0 auto;
    width: 18px; height: 18px;
    border-radius: 5px;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,.12);
}
.cy-layer-label { flex: 1 1 auto; font-size: 14px; color: var(--text); }

/* toggle-switch */
.cy-switch { position: relative; flex: 0 0 auto; width: 38px; height: 22px; }
.cy-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.cy-switch-track {
    position: absolute; inset: 0;
    background: #cfcfcf;
    border-radius: var(--pill);
    transition: background .18s var(--ease);
}
.cy-switch-track::before {
    content: ""; position: absolute;
    top: 2px; left: 2px; width: 18px; height: 18px;
    background: #fff; border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,.3);
    transition: transform .18s var(--ease);
}
.cy-switch input:checked + .cy-switch-track { background: var(--accent); }
.cy-switch input:checked + .cy-switch-track::before { transform: translateX(16px); }

.cy-layers-divider { height: 1px; background: var(--border); margin: 8px 0; }

.cy-layers-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: #fff8e6;
    border: 1px solid #ffe0a3;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.45;
    color: #5b4300;
}
.cy-warn-tri {
    flex: 0 0 auto;
    width: 0; height: 0;
    margin-top: 2px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 14px solid #ffb300;
    position: relative;
}

/* ---- Objekt-popup (ol.Overlay) ---- */
.cy-popup {
    position: absolute;
    min-width: 220px;
    max-width: 300px;
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    padding: 14px 16px 16px;
    transform: translate(-50%, -100%);
    margin-top: -14px;
    font-size: 13px;
    color: var(--text);
    cursor: move;
    user-select: none;
}
.cy-popup-moved::after { display: none; }   /* dölj pilen när popupen dragits undan */
.cy-popup-close { cursor: pointer; }
.cy-popup::after {
    content: "";
    position: absolute;
    left: 50%; bottom: -8px;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--white);
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.12));
}
.cy-popup-close {
    position: absolute; top: 6px; right: 6px;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border: 0; background: transparent; border-radius: 50%;
    color: var(--text-light); cursor: pointer;
}
.cy-popup-close:hover { background: var(--bg-hover); }
.cy-popup-close .material-symbols-outlined { font-size: 18px; }

.cy-popup-cat {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 600; letter-spacing: .03em;
    text-transform: uppercase;
    padding: 3px 8px; border-radius: var(--pill);
    margin-bottom: 8px;
}
.cy-popup-title { font-size: 15px; font-weight: 700; line-height: 1.3; margin-bottom: 8px; padding-right: 18px; }
.cy-popup-row { display: flex; gap: 8px; margin: 4px 0; }
.cy-popup-row .k { flex: 0 0 92px; color: var(--text-light); }
.cy-popup-row .v { flex: 1 1 auto; color: var(--text); }
.cy-popup-desc { margin-top: 8px; padding-top: 8px; border-top: 1px solid #f0f0f0; color: var(--text-soft); line-height: 1.45; }
.cy-popup-warn {
    display: flex; align-items: center; gap: 8px;
    margin-top: 10px; padding: 8px 10px;
    background: #fff3d6; border: 1px solid #ffd98a; border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 500; color: #6b4e00;
}
.cy-popup-warn .material-symbols-outlined { font-size: 18px; color: #c47d00; }

/* ============================ DYNAMISK LEGEND ============================ */
.cy-legend {
    position: fixed;
    bottom: calc(56px + var(--sab)); left: calc(var(--edge) + var(--sal));
    z-index: 1150;
    width: 210px; max-width: calc(100vw - 2*var(--edge));
    background: rgba(255,255,255,0.94);
    backdrop-filter: blur(2px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    font-size: 12px; color: var(--text-soft);
    transition: opacity .2s var(--ease), visibility .2s;
}
/* dölj legenden när rutt-kortet (vänster) är öppet — de delar hörn */
body.cy-route-open .cy-legend { opacity: 0; visibility: hidden; pointer-events: none; }
.cy-legend__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; cursor: pointer; user-select: none;
}
.cy-legend__header:hover { background: rgba(0,0,0,.03); }
.cy-legend__title { font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--text); }
.cy-legend__toggle { font-size: 18px; color: var(--text-light); transition: transform .2s ease; }
.cy-legend--collapsed .cy-legend__toggle { transform: rotate(180deg); }
.cy-legend__body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .25s ease; }
.cy-legend--collapsed .cy-legend__body { grid-template-rows: 0fr; }
.cy-legend__items {
    overflow: hidden;
    overflow-y: auto;
    /* landskaps-iPhone: legenden får inte bli högre än skärmen — scrolla istället */
    max-height: calc(100vh - 210px);
    max-height: calc(100dvh - 210px);
    padding: 0 12px;
}
.cy-legend:not(.cy-legend--collapsed) .cy-legend__items { padding-bottom: 10px; }
.cy-legend__group { font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-light); margin: 8px 0 2px; }
.cy-legend__item { display: flex; align-items: center; gap: 9px; padding: 3px 0; line-height: 1.25; }
.cy-legend__sw { flex: 0 0 auto; width: 18px; display: grid; place-items: center; }
.cy-legend__box { width: 16px; height: 16px; border-radius: 3px; }
.cy-legend__line { width: 18px; height: 0; }
.cy-legend__img { width: 16px; height: 16px; object-fit: contain; }
.cy-legend__tri { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 12px solid #ffb300; }
.cy-legend__label { flex: 1 1 auto; }

/* ============================ MOBIL ============================ */
@media (max-width: 760px) {
    /* lagerpanel -> bottom sheet */
    #cyLayersPanel {
        top: auto; bottom: 0; left: 0; right: 0;
        width: 100%; max-width: none;
        max-height: 75vh;       /* fallback för äldre iOS */
        max-height: 75dvh;
        border-radius: 18px 18px 0 0;
        padding: 16px 18px calc(22px + var(--sab));
        animation: cy-sheet-up .26s var(--ease);
    }
    @keyframes cy-sheet-up { from { transform: translateY(100%); } to { transform: none; } }

    .cy-legend { bottom: calc(54px + var(--sab)); left: calc(var(--edge) + var(--sal)); width: 188px; }
}
