/*
Copyright: (c) 2026 Jörn Menne
Licensed under the Apache License, Version 2.0
See NOTICE file for details.
*/

/* Overlay controls on the map, placed like the Leaflet zoom buttons (top-left) */
#map-container{
    /* Same size as the Leaflet zoom buttons on touch devices */
    --control-size: 30px;
    --control-inset: 10px;

    position: relative;
}

#gps-button,
#nomi-form{
    position: absolute;
    top: var(--control-inset);
    /* Leaflet controls use z-index 800, the map panes 400 */
    z-index: 1000;
}

/* Same look as the Leaflet zoom buttons, mirrored to the top-right corner */
#gps-button{
    right: var(--control-inset);
    width: 44px;
    height: 44px;
    padding: 0;

    display: grid;
    place-items: center;

    color: black;
    background-color: #fff;
    border: 2px solid rgb(0 0 0 / 0.2);
    border-radius: 4px;
    box-shadow: 0 1px 5px rgb(0 0 0 / 0.65);
    cursor: pointer;

    svg{
        width: 22px;
        height: 22px;
    }

    /* Only on devices with a real pointer, so taps don't leave a stuck hover */
    @media (hover: hover){
        &:hover{
            background-color: #f4f4f4;
        }
    }
}

/* Search bar is centered and 78% wide, but never reaches the zoom or GPS buttons */
#nomi-form{
    left: 50%;
    translate: -50% 0;
    width: min(78%, calc(100% - 2 * (var(--control-inset) * 2 + var(--control-size) + 4px)));
    /* Matches the width of the form inputs on wide desktop screens */
    max-width: 38rem;
    /* Between one zoom button (30px) and both together (60px) */
    height: 44px;
    margin: 0;

    input{
        width: 100%;
        height: 100%;
        padding: 0 0.75rem;

        font: inherit;
        font-size: 1rem; /* 16px avoids zoom on iOS */
        color: black;
        background-color: #fff;
        border: 1px solid rgb(0 0 0 / 0.15);
        border-radius: 22px;
        box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
    }

    /* Floating hint inside the input, hidden as soon as the user types or focuses */
    label{
        position: absolute;
        left: 0.75rem;
        top: 50%;
        translate: 0 -50%;

        color: #555;
        white-space: nowrap;
        pointer-events: none;
        transition: opacity var(--dur);
    }
    input:focus + label,
    input:not(:placeholder-shown) + label{
        opacity: 0;
    }
}

@keyframes details-in{
    from{
        opacity: 0;
        transform: translateY(-0.5rem);
    }
}

/* Form below the map */
.create-form{
    max-width: 40rem;
    margin: 1.5rem auto;
    padding: 0 1rem;

    display: grid;
    gap: 0.5rem;

    label{
        display: block;
        font-weight: bold;
    }

    /* Starts at 4 lines and grows with the text; browsers without field-sizing keep the drag handle */
    textarea{
        field-sizing: content;
        min-height: 4lh;
        max-height: 20lh;
        height: auto;
        resize: vertical;
    }

    input[type="checkbox"]{
        width: 1.5rem;
        height: 1.5rem;
        margin: 0;
        flex-shrink: 0;
        accent-color: var(--dark-blue);
    }

    p{
        margin: 0;
        font-size: 0.9rem;
    }

    .checkbox-group{
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    fieldset{
        display: grid;
        gap: 0.5rem;
        margin: 0;
        padding: 1rem;

        border: 2px solid var(--gray);
        border-radius: var(--border-radius);
    }

    legend{
        padding: 0 0.4rem;
        font-weight: bold;
    }

    /* Groups without a border: the legend acts as a heading */
    fieldset.field-group{
        margin: 1rem 0 0;
        padding: 0;
        border: 0;
    }

    .field-group legend{
        padding: 0;
        margin-bottom: 0.5rem;
        font-size: 1.1rem;
    }

    /* Shown once both coordinates are filled in (empty required inputs are :invalid).
       Visual only: the screen-reader message comes from announcePosition() in locationPicker.js */
    .position-chip{
        display: none;
        justify-self: start;
        padding: 0.3rem 0.75rem;

        font-size: 0.85rem;
        font-weight: bold;
        color: white;
        background-color: var(--dark-blue);
        border-radius: 999px;
    }

    fieldset:has(#latitude:valid):has(#longitude:valid) .position-chip{
        display: block;
    }

    details{
        summary{
            display: flex;
            align-items: center;
            min-height: 2.75rem;
            font-weight: bold;
            cursor: pointer;
        }
        label{
            margin-top: 0.5rem;
        }

        /* Fades the content in when opened; closing stays instant */
        &[open] > :not(summary){
            animation: details-in var(--dur) ease-out;
        }
    }

    .button{
        justify-self: start;
        margin-top: 0.5rem;
    }
}
