/* Precinct map viewer (ElectionMap*/index.html). Loaded after Site.css, which supplies the tokens,
   masthead, buttons and status message. The map script (jpmap.cmp.js) and jQuery Mobile generate
   the legend and precinct-detail markup, so the selectors below target their ids and ui-* classes. */

/* No footer on this page, so the light page ground runs to the bottom instead of Site.css's navy html. */
html {
    background: var(--jpcc-bg);
}

.masthead-compact .wrap {
    padding-bottom: 0.6rem;
    padding-top: 0.6rem;
}

.masthead-compact .seal {
    height: 64px;
    width: 64px;
}

.masthead-compact .masthead-officeholder {
    font-size: 1.35rem;
}

/* jQuery Mobile adds a "loading" box and a clear-search link that only its own stylesheet hides. */
.ui-loader,
.ui-input-clear {
    display: none !important;
}

.map-content {
    padding-bottom: 2.5rem;
    padding-top: 1.5rem;
}

.map-section {
    background: var(--jpcc-surface);
    border: 1px solid var(--jpcc-border);
    border-radius: 8px;
    display: grid;
    gap: 1rem;
    padding: 1.25rem;
}

.map-bar {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    justify-content: space-between;
}

.map-kicker {
    color: var(--jpcc-muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin: 0;
    text-transform: uppercase;
}

.map-kicker span {
    color: var(--jpcc-gold-deep);
    padding: 0 0.4em;
}

.map-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

#activityIndicator {
    align-items: center;
    background: var(--jpcc-surface);
    border: 1px solid var(--jpcc-border-strong);
    border-radius: 6px;
    box-shadow: 0 6px 15px rgba(6, 33, 53, 0.2);
    color: var(--jpcc-navy);
    display: flex;
    font-weight: 700;
    gap: 0.75rem;
    left: 50%;
    padding: 0.85rem 1.1rem;
    position: fixed;
    top: 45%;
    transform: translate(-50%, -50%);
    z-index: 30;
}

#activityIndicator img {
    height: 24px;
    width: 24px;
}

#legendAndCanvas {
    display: grid;
    gap: 1rem 1.25rem;
    grid-template-areas:
        "title title"
        "legend map";
    grid-template-columns: auto minmax(0, 1fr);
}

#raceTitle {
    font-size: clamp(1.3rem, 2.5vw, 1.55rem);
    grid-area: title;
    margin: 0;
}

/* Visible by default; the Legend button and "Hide legend" toggle it inline. */
#legendContainer {
    grid-area: legend;
    width: 260px;
}

#legendContainer form {
    margin-bottom: 0.6rem;
}

#legendContainer input {
    background: #fff;
    border: 1px solid var(--jpcc-border-strong);
    border-radius: 4px;
    color: var(--jpcc-text);
    font-size: 0.9rem;
    min-height: 38px;
    padding: 0.45rem 0.6rem;
    width: 100%;
}

#legendContainer input:focus {
    border-color: var(--jpcc-navy);
    box-shadow: 0 0 0 2px rgba(10, 49, 77, 0.15);
    outline: none;
}

#legendm {
    border: 1px solid var(--jpcc-border);
    border-radius: 6px;
    list-style: none;
    margin: 0;
    overflow: hidden;
    padding: 0;
}

/* The script writes "list-style: disc; color: <candidate color>" inline on each row. */
#legendm li {
    align-items: center;
    border-top: 1px solid var(--jpcc-border);
    color: var(--jpcc-text) !important;
    display: flex;
    font-size: 0.88rem;
    font-weight: 600;
    gap: 0.6rem;
    list-style: none !important;
    padding: 0.5rem 0.75rem;
}

#legendm li:first-child {
    border-top: 0;
}

#legendm .ui-li-divider {
    background: var(--jpcc-navy-dark);
    color: #fff !important;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#legendm .ui-li-divider:last-child {
    background: var(--jpcc-bg-soft);
    padding: 0;
}

.showLegendButton {
    color: var(--jpcc-navy);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 0.5rem 0.75rem;
    width: 100%;
}

.showLegendButton:hover {
    text-decoration: underline;
}

.legendBox {
    border: 1px solid rgba(6, 33, 53, 0.35);
    border-radius: 3px;
    flex: 0 0 auto;
    height: 14px;
    width: 14px;
}

.blackText {
    color: var(--jpcc-text);
    overflow-wrap: anywhere;
}

.map-frame {
    background: var(--jpcc-bg-soft);
    border: 1px solid var(--jpcc-border);
    border-radius: 6px;
    grid-area: map;
    min-width: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* The script sizes #canvas inline (720 x 1000 desktop, 320 x 776 iPhone). */
#canvas {
    background: #fff;
    margin: 0 auto;
}

#paper {
    position: relative;
}

#paper svg {
    display: block;
}

/* A tooltip: on desktop the map script moves it beside the cursor by setting top/left inline.
   A fixed height keeps it from stretching if a bottom offset (phone rule below) also applies. */
#precinctDetails {
    background: var(--jpcc-navy);
    border-radius: 6px;
    border-top: 3px solid var(--jpcc-gold);
    box-shadow: 0 6px 15px rgba(6, 33, 53, 0.2);
    color: #d9e2ea;
    display: none;
    font-size: 0.9rem;
    height: max-content;
    left: 0;
    line-height: 1.45;
    padding: 0.85rem 1rem;
    position: fixed;
    top: 0;
    width: min(320px, calc(100vw - 1rem));
    z-index: 20;
}

#precinctDetails h2 {
    color: #fff;
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
}

#precinctDetails h2 + br {
    display: none;
}

#closeButton {
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 0.6rem;
    padding: 0.35rem 0.75rem;
}

@media (max-width: 760px) {
    #legendAndCanvas {
        grid-template-areas:
            "title"
            "legend"
            "map";
        grid-template-columns: minmax(0, 1fr);
    }

    #legendContainer {
        width: auto;
    }
}

@media (max-width: 640px) {
    /* Site.css hides the masthead ghost button on phones (it duplicates the notice link there); here it is the only way back. */
    .masthead-compact .masthead-actions .btn-ghost-light {
        display: inline-flex;
    }

    .map-section {
        padding: 1rem;
    }

    /* No room for a cursor tooltip on a phone: dock the card at the bottom, overriding the script's inline top/left. */
    #precinctDetails {
        bottom: 0.5rem;
        left: 0.5rem !important;
        top: auto !important;
    }

    .map-tools .btn {
        flex: 1 1 auto;
    }
}
