/* sunnyray map UI, shared by the web and MAUI apps. Link it after the host page's own styles. */

html, body {
    height: 100%;
    margin: 0;
}

/* The map controls' font, for everything else too (the startup percentage, the error bar). */
body {
    font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
}

/* --map-top: room a host page leaves above the map (a navbar); none by default. */
.map-container {
    position: fixed;
    inset: var(--map-top, 0px) 0 0 0;
}

/* The app's bar along the top (MapView with OnMenu): menu button and place search. The host sets --map-top to
   --app-bar-height so the map starts below it. */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 3;
    box-sizing: border-box;
    height: var(--app-bar-height, 52px);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px 0 4px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

    .app-bar .location-search {
        flex: 1;
    }

        .app-bar .location-search input {
            padding-top: 8px;
            padding-bottom: 8px;
            font-size: 15px;
        }

.app-bar-menu {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: #333;
    cursor: pointer;
}

    .app-bar-menu:active {
        background: rgba(0, 0, 0, 0.08);
    }

/* Everything along the bottom edge: the pin card and the map credits above the bar. Not a transform-centred
   box: that would trap the day dialog (position: fixed) inside it. */
.bottom-area {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 10px;
    z-index: 2;
    box-sizing: border-box;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

/* The pin card at the left, the credits (the "i" button) at the right, just over the bar. */
.above-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
}

.attribution-holder {
    margin-left: auto;
    pointer-events: auto;
}

    .attribution-holder .maplibregl-ctrl {
        float: none;
        margin: 0;
    }

/* The bottom bar: search, the switches, the time of day and the map's own buttons, each in a segment of its own. */
.bottom-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    pointer-events: none;
}

.bar-segment {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    font: 13px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
    pointer-events: auto;
}

    .bar-segment[hidden] {
        display: none;
    }

.search-segment {
    flex: 0 1 260px;
    min-width: 160px;
}

.switch-segment {
    position: relative;
    z-index: 1; /* its menu goes over the pin card and the rest of the bar */
    flex: none;
    gap: 4px;
}

/* The Config button's menu, rising from the bar; the switches lie on their side in it. */
.config-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1), 0 -4px 12px rgba(0, 0, 0, 0.15);
    animation: config-rise 0.15s ease-out;
}

    .config-menu .bar-switch {
        flex-direction: row-reverse;
        justify-content: space-between;
        gap: 16px;
        padding: 7px 8px;
        font-size: 12px;
    }

/* A choice of one among a few, in the menu: its name at the left, the options side by side at the right. */
.config-choice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 8px;
    font: 600 12px/12px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
    white-space: nowrap;
}

.choice-options {
    display: flex;
    border-radius: 9px;
    background: #e6e8ec;
    padding: 2px;
}

    .choice-options button {
        padding: 4px 9px;
        border: 0;
        border-radius: 7px;
        background: none;
        color: #333;
        font: inherit;
        cursor: pointer;
    }

        .choice-options button.on {
            background: #1b2a4a;
            color: #fff;
        }

        .choice-options button:hover:not(:disabled):not(.on) {
            background: #d6d9df;
        }

        .choice-options button:disabled {
            opacity: 0.45;
            cursor: default;
        }

        .choice-options button:focus-visible {
            outline: 2px solid #1b6ec2;
            outline-offset: 1px;
        }

.config-backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: auto;
}

/* Narrower than this, the bar wraps and the segment starts at the screen's left edge. */
@media (max-width: 419px) {
    .config-menu {
        left: 0;
        right: auto;
    }
}

@keyframes config-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .config-menu {
        animation: none;
    }
}

.controls-segment {
    flex: none;
    gap: 6px;
    padding: 4px 6px;
}

/* Styled like the MapLibre controls they sit next to. */
.location-search {
    position: relative;
    flex: 1;
    min-width: 0;
}

    .location-search input {
        box-sizing: border-box;
        width: 100%;
        padding: 6px 50px 6px 10px; /* room for the spinner and the clear button */
        border: 0;
        border-radius: 4px;
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
        font: 13px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
        color: #333;
        background: #fff;
    }

        .location-search input:focus {
            outline: none;
            box-shadow: inset 0 0 0 2px #1b6ec2;
        }

        /* The browser's own clear button; ours (.location-clear) sits at the edge instead. */
        .location-search input::-webkit-search-cancel-button {
            -webkit-appearance: none;
            appearance: none;
            display: none;
        }

/* Clears the box: a square at its right edge, as tall as the input. */
.location-clear {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0 4px 4px 0;
    background: none;
    color: #777;
    cursor: pointer;
}

    .location-clear:hover {
        color: #333;
    }

/* Turns while a search is on its way; left of the clear button. */
.location-spinner {
    position: absolute;
    top: calc(50% - 7px);
    right: 28px;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(27, 110, 194, 0.2);
    border-top-color: #1b6ec2;
    border-radius: 50%;
    animation: location-spin 0.7s linear infinite;
    pointer-events: none;
}

@keyframes location-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .location-spinner {
        animation-duration: 2s;
    }
}

.location-results {
    position: absolute;
    bottom: calc(100% + 10px); /* opens upwards from the bottom bar */
    left: 0;
    right: 0;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1), 0 -4px 12px rgba(0, 0, 0, 0.15);
    font: 13px/18px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
}

    .location-results li {
        display: flex;
        flex-direction: column;
        padding: 6px 10px;
        cursor: pointer;
    }

        .location-results li.active {
            background: #eef3fb;
        }

    /* In a bar at the top of the screen (the app), the suggestions drop down instead. */
    .location-search.down .location-results {
        top: calc(100% + 8px);
        bottom: auto;
        z-index: 3;
        box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .location-results .location-detail {
        color: #777;
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .location-results .location-message {
        color: #777;
        cursor: default;
    }

.map-toggle {
    padding: 6px 12px;
    border: 0;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    color: #333;
    font: 600 12px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
    white-space: nowrap;
    cursor: pointer;
}

    .map-toggle:hover:not(:disabled) {
        background: #f2f2f2;
    }

    .map-toggle.active,
    .map-toggle.active:hover:not(:disabled) {
        background: #1b2a4a;
        color: #fff;
    }

    .map-toggle:disabled {
        opacity: 0.6;
        cursor: default;
    }

/* Switches: a small slide switch with its name underneath; the 3D/2D button has an icon in its place. */
.bar-switch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 56px;
    padding: 4px 4px 2px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: #333;
    font: 600 10px/12px "Helvetica Neue", Arial, Helvetica, sans-serif;
    white-space: nowrap;
    cursor: pointer;
}

    .bar-switch:hover:not(:disabled) {
        background: #f2f2f2;
    }

    .bar-switch:disabled {
        opacity: 0.45;
        cursor: default;
    }

    .bar-switch:focus-visible {
        outline: 2px solid #1b6ec2;
        outline-offset: 1px;
    }

.switch-track {
    position: relative;
    flex: none;
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: #b9bec7;
    transition: background 0.15s;
}

    .switch-track::after {
        content: "";
        position: absolute;
        top: 2px;
        left: 2px;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: #fff;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
        transition: transform 0.15s;
    }

.bar-switch.on .switch-track {
    background: #1b2a4a;
}

    .bar-switch.on .switch-track::after {
        transform: translateX(14px);
    }

.view-icon {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 18px;
    border-radius: 4px;
    background: #1b2a4a;
    color: #fff;
    font: 700 11px/1 "Helvetica Neue", Arial, Helvetica, sans-serif;
    letter-spacing: 0.5px;
}

@media (prefers-reduced-motion: reduce) {
    .switch-track,
    .switch-track::after {
        transition: none;
    }
}

/* The map's zoom, compass and locate buttons, laid out in a row inside their segment of the bar. */
.controls-segment .maplibregl-ctrl-group {
    display: flex;
    margin: 0;
    float: none;
    box-shadow: none;
    border: 1px solid rgba(0, 0, 0, 0.18);
}

    .controls-segment .maplibregl-ctrl-group:not(:empty) button + button {
        border-top: 0;
        border-left: 1px solid #ddd;
    }

/* Time of day for the shadows (or the legend of the sun-hours map in its place). */
.time-bar {
    flex: 1 1 300px;
    min-width: 0;
    gap: 12px;
    padding: 6px 8px 6px 14px;
}

    .time-bar[hidden] {
        display: none;
    }

    .time-bar .time-label {
        min-width: 3.2em;
        font-size: 15px;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
    }

    .time-bar .time-slider {
        position: relative;
        flex: 1;
        min-width: 0;
        display: flex;
    }

    .time-bar input[type=range] {
        flex: 1;
        min-width: 0;
        margin: 0;
        accent-color: #1b2a4a;
        cursor: pointer;
    }

/* The day's cloud forecast, hour by hour, right under the slider's track: yellow = sun, grey = overcast. Inset by
   about half the thumb so that each hour sits under its place on the track. */
.cloud-hours {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: -7px;
    height: 5px;
    display: flex;
    gap: 1px;
}

    .cloud-hours span {
        flex: 1;
        border-radius: 1px;
        background: color-mix(in srgb, #8a93a6 var(--cloud, 0%), #f3c33c);
    }

        .cloud-hours span.night {
            background: #1b2a4a;
            opacity: 0.35;
        }

/* Legend of the sun-hours map, in place of the time bar. Colours match SUN_HOURS_COLORS in shadow-worker.js. */
.sun-hours-legend {
    padding: 6px 14px 6px 8px;
}

    .sun-hours-legend .legend-title {
        font-weight: 600;
        white-space: nowrap;
    }

    .sun-hours-legend .legend-end {
        color: #555;
        font-size: 12px;
        white-space: nowrap;
    }

    .sun-hours-legend .legend-ramp {
        flex: 1;
        min-width: 40px;
        height: 12px;
        border-radius: 6px;
        background: linear-gradient(to right, rgb(215, 48, 39), rgb(250, 210, 60), rgb(26, 152, 80));
    }

/* A short status line above the bar, such as the cloud forecast loading. */
.map-note {
    pointer-events: auto;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    font: 12px/16px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
}

/* Card for the pinned spot: when the sun is up and when it reaches the pin. Bottom left, above the bottom bar. */
.pin-card {
    box-sizing: border-box;
    width: min(300px, calc(100% - 20px));
    max-height: calc(100vh - 170px);
    overflow-y: auto;
    pointer-events: auto;
    padding: 10px 12px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    font: 13px/18px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
}

.pin-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.pin-title {
    font-size: 15px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.pin-close {
    flex: none;
    width: 24px;
    height: 24px;
    margin: -2px -4px 0 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: #777;
    font-size: 20px;
    line-height: 22px;
    cursor: pointer;
}

    .pin-close:hover {
        background: #f2f2f2;
        color: #333;
    }

.pin-sub,
.pin-foot {
    color: #777;
    font-size: 12px;
}

.pin-foot {
    margin-top: 8px;
    font-size: 11px;
    line-height: 15px;
}

.pin-note {
    margin-top: 6px;
}

    .pin-note.shade {
        color: #a6291f;
        font-weight: 600;
    }

.pin-times {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 12px;
    margin: 8px 0 0;
}

    .pin-times dt {
        color: #555;
    }

    .pin-times dd {
        margin: 0;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
    }

    /* The sun's own arrival and departure, set apart from the flat-horizon sunrise and sunset. */
    .pin-times.sun {
        padding-top: 8px;
        border-top: 1px solid #e6e6e6;
    }

        .pin-times.sun dd {
            color: #b35c00;
        }

.pin-now {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e6e6e6;
}

/* Day button in the time bar, and its dialog. */
.time-bar .day-button {
    min-width: 4.5em;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0.3);
}

.day-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    box-sizing: border-box;
    width: min(360px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    overflow-y: auto;
    padding: 16px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    font: 13px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
    color: #333;
}

    .day-dialog h2 {
        margin: 0 0 12px;
        font-size: 16px;
        font-weight: 600;
    }

    .day-dialog input[type=date] {
        box-sizing: border-box;
        width: 100%;
        padding: 6px 10px;
        border: 0;
        border-radius: 4px;
        box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
        font: inherit;
        font-size: 15px;
        color: inherit;
    }

        .day-dialog input[type=date]:focus {
            outline: none;
            box-shadow: 0 0 0 2px #1b6ec2;
        }

.day-presets {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 12px 0 16px;
}

.day-preset {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    background: none;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

    .day-preset:hover {
        background: #f2f2f2;
    }

    .day-preset.active {
        background: #eef3fb;
        font-weight: 600;
    }

    .day-preset-date {
        color: #777;
        white-space: nowrap;
    }

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}


/* A word on the sun at the pin, right over it ("Sun until 16:40"): amber in the sun, slate in the shade. */
.pin-label {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%);
    padding: 1px 9px;
    border-radius: 11px;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    font: 600 12px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
    font-variant-numeric: tabular-nums;
    color: #333;
    white-space: nowrap;
    pointer-events: none;
}

    .pin-label[hidden] {
        display: none;
    }

    .pin-label.sun {
        background: #fff3d1;
        color: #8a4a00;
    }

    .pin-label.shade {
        background: #e8ebf5;
        color: #2f3b66;
    }

/* The sun's path around the pin (sun-path.js). Clicks go through it to the map. */
.sun-path {
    pointer-events: none;
}

    .sun-path svg {
        display: block;
        overflow: visible;
    }

    .sun-path .horizon {
        fill: rgba(255, 255, 255, 0.14);
        stroke: rgba(255, 255, 255, 0.9);
        stroke-width: 2.5;
    }

    .sun-path .spoke {
        stroke: rgba(255, 255, 255, 0.9);
        stroke-width: 1.5;
        stroke-dasharray: 3 4;
    }

    .sun-path polyline {
        fill: none;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .sun-path .halo {
        stroke: rgba(255, 255, 255, 0.9);
        stroke-width: 8;
    }

    .sun-path .lit {
        stroke: #f5a200;
        stroke-width: 5;
    }

    .sun-path .blocked {
        stroke: #5a6488;
        stroke-width: 4;
        stroke-dasharray: 1 7;
    }

    .sun-path .ray {
        stroke: #f5a200;
        stroke-width: 2;
    }

    .sun-path .sun {
        fill: #ffc61a;
        stroke: #fff;
        stroke-width: 2.5;
    }

        .sun-path .sun.blocked {
            fill: #8a93b3;
        }
