/* =====================================================================================================================
   Sharing: the bell and inbox, toasts, the Sharing panel, the share dialog, the join page, Shared with me.
   Mobile first: every button is at least 44 px tall on a phone or any coarse pointer, text is 13-14 px, nothing scrolls sideways,
   and the sheets fill the width of a narrow screen (tests/e2e/sharing.js checks 412 x 915 and 360 x 740).
   Loaded after app.css, so it can build on its variables.
   ===================================================================================================================== */

.hg-touch {
    min-height: 36px;
}

@media (max-width: 640px), (pointer: coarse) {
    .hg-touch {
        min-height: 44px;
    }

    .hg-icon-button.hg-touch {
        min-width: 44px;
    }
}

.hg-alert,
.hg-okay {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.hg-alert {
    background: rgba(255, 107, 82, 0.1);
    border: 1px solid rgba(255, 107, 82, 0.4);
    color: #ffb4a6;
}

.hg-okay {
    background: rgba(126, 200, 120, 0.1);
    border: 1px solid rgba(126, 200, 120, 0.35);
    color: #bfe6ba;
}

.hg-subhead {
    margin: 14px 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--hg-text-dim);
    font-weight: 600;
}

.hg-badge {
    flex: 0 0 auto;
    padding: 1px 6px;
    border: 1px solid var(--hg-border);
    border-radius: 999px;
    font-size: var(--hg-fs-10);
    color: var(--hg-text-dim);
    white-space: nowrap;
}

/* ------------------------------------------------------------------------------------------------- the header -- */

/*
 * The header's right-hand buttons are two wrappers: the map tools (pin, path, measure, home, panels) and the account buttons (the bell,
 * Personalization, Debug, Sign out). On a wide screen the wrappers are not boxes at all, so the header is exactly as it was.
 */
.hg-toolbar__tools,
.hg-toolbar__account {
    display: contents;
}

/*
 * On a phone (portrait) the header is one row of 44 px (the sync mark, the basemap chips and the account buttons) and the map tools are a DOCK along
 * the bottom, in reach of a thumb, above the coordinate bar: the header used to be two rows (96 px) with the tools under the chips. Every button is a
 * real touch target. The shell gets a third row tall enough for the dock, so the map and its bottom sheet end above it.
 */
@media (max-width: 640px) and (min-height: 481px) {
    :root {
        --hg-toolbar-height: 52px;
        --hg-dock-height: 56px;
    }

    .hg-shell {
        grid-template-rows: var(--hg-toolbar-height) 1fr calc(var(--hg-statusbar-height) + var(--hg-dock-height));
    }

    .hg-shell > .hg-statusbar {
        align-self: end;
        height: var(--hg-statusbar-height);
    }

    .hg-toolbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: 44px;
        align-content: end;
        column-gap: 6px;
        row-gap: 2px;
        padding-bottom: 2px;
    }

    .hg-toolbar > .hg-toolbar__group:first-child {
        grid-column: 1;
        grid-row: 1;
    }

    .hg-toolbar > .hg-toolbar__group--center {
        grid-column: 2;
        grid-row: 1;
        justify-content: flex-start;
    }

    .hg-toolbar > .hg-toolbar__group--right {
        display: contents;
    }

    .hg-toolbar .hg-toolbar__account {
        display: flex;
        grid-column: 3;
        grid-row: 1;
        align-items: center;
        gap: 2px;
    }

    .hg-toolbar .hg-toolbar__tools {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(var(--hg-statusbar-height) + env(safe-area-inset-bottom, 0px));
        height: var(--hg-dock-height);
        z-index: 5;
        display: flex;
        align-items: center;
        justify-content: space-around;
        gap: 2px;
        padding: 0 6px;
        background: var(--hg-bg-panel);
        border-top: 1px solid var(--hg-border);
    }

    .hg-toolbar .hg-toolbar__tools .hg-toolbar__sep {
        display: none;
    }

    .hg-toolbar .hg-toolbar__group .hg-toolbar__tools .hg-icon-button {
        flex: 1 1 0;
        width: auto;
        max-width: 64px;
        height: 48px;
        font-size: 17px;
    }

    .hg-toolbar .hg-toolbar__group .hg-toolbar__account .hg-icon-button {
        width: 42px;
        height: 44px;
        font-size: 15px;
    }

    .hg-toolbar .hg-chip {
        min-height: 40px;
    }
}

/* The narrowest phones (360 px): the account buttons give up 4 px each so the four basemap chips still fit beside them. */
@media (max-width: 400px) and (min-height: 481px) {
    .hg-toolbar .hg-toolbar__group .hg-toolbar__account .hg-icon-button {
        width: 38px;
    }

    .hg-toolbar .hg-toolbar__account {
        gap: 0;
    }

    .hg-toolbar .hg-toolbar__group--center {
        gap: 4px;
    }

    .hg-toolbar .hg-toolbar__group--center .hg-chip {
        padding-left: 7px;
        padding-right: 7px;
    }
}

/* ------------------------------------------------------------------------------------------------ bell + inbox -- */

.hg-bell {
    position: relative;
}

.hg-bell__badge {
    position: absolute;
    top: 1px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--hg-danger);
    color: #1a1a10;
    font-size: var(--hg-fs-10);
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}

.hg-inbox {
    position: fixed;
    z-index: 30;
    top: calc(var(--hg-toolbar-height) + env(safe-area-inset-top, 0px));
    right: 8px;
    width: min(380px, calc(100vw - 16px));
    max-height: calc(100dvh - var(--hg-toolbar-height) - var(--hg-statusbar-height) - 16px);
    display: flex;
    flex-direction: column;
    background: var(--hg-bg-panel);
    border: 1px solid var(--hg-border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.hg-inbox__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 12px;
    border-bottom: 1px solid var(--hg-border);
}

.hg-inbox__head h2 {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--hg-text-dim);
}

.hg-inbox__head h2 i {
    margin-right: 6px;
    color: var(--hg-accent);
}

.hg-inbox__head .hg-button {
    width: auto;
}

.hg-inbox__list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
}

.hg-inbox__list li + li {
    border-top: 1px solid var(--hg-border);
}

.hg-inbox__button {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--hg-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}

.hg-inbox__button:hover {
    background: rgba(255, 255, 255, 0.04);
}

.hg-inbox__dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin-top: 5px;
    border-radius: 50%;
    background: transparent;
}

.hg-inbox__item--unread .hg-inbox__dot {
    background: var(--hg-accent);
}

.hg-inbox__item--unread .hg-inbox__line {
    font-weight: 600;
}

.hg-inbox__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.hg-inbox__line {
    overflow-wrap: anywhere;
}

.hg-inbox__when {
    font-size: var(--hg-fs-11);
    color: var(--hg-text-dim);
}

.hg-inbox__empty {
    margin: 0;
    padding: 14px 12px;
}

@media (max-width: 640px) {
    .hg-inbox {
        left: 8px;
        right: 8px;
        width: auto;
    }
}

/* ----------------------------------------------------------------------------------------------------- toasts -- */

.hg-sharetoasts {
    position: fixed;
    z-index: 35;
    top: calc(var(--hg-toolbar-height) + env(safe-area-inset-top, 0px) + 6px);
    left: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.hg-sharetoast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(440px, 100%);
    padding: 4px 4px 4px 12px;
    border-radius: 10px;
    background: rgba(28, 33, 24, 0.97);
    border: 1px solid rgba(255, 209, 102, 0.45);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    font-size: 13px;
    line-height: 1.4;
}

.hg-sharetoast > i {
    flex: 0 0 auto;
    color: var(--hg-accent);
}

.hg-sharetoast__text {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 4px;
    background: transparent;
    border: none;
    color: var(--hg-text);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.hg-sharetoast__dismiss {
    flex: 0 0 auto;
    min-width: 36px;
    background: transparent;
    border: none;
    color: var(--hg-text-dim);
    cursor: pointer;
}

/* ------------------------------------------------------------------------------------------------------ modal -- */

.hg-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.hg-modal__backdrop {
    position: absolute;
    inset: 0;
    padding: 0;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    cursor: default;
}

.hg-modal__sheet {
    position: relative;
    width: min(520px, 100%);
    max-height: 92dvh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    background: var(--hg-bg-panel);
    border: 1px solid var(--hg-border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}

@media (min-width: 641px) {
    .hg-modal {
        align-items: center;
    }

    .hg-modal__sheet {
        border-radius: 12px;
    }
}

.hg-modal__head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hg-modal__head h2 {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 15px;
    overflow-wrap: anywhere;
}

.hg-modal__head h2 i {
    margin-right: 6px;
    color: var(--hg-accent);
}

.hg-picklist {
    list-style: none;
    margin: 0 0 4px;
    padding: 0;
}

.hg-picklist li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--hg-border);
}

.hg-picklist__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 14px;
}

.hg-picklist__name i {
    margin-right: 6px;
    color: var(--hg-text-dim);
}

.hg-picklist .hg-button {
    flex: 0 0 auto;
    width: auto;
    min-width: 84px;
}

/* ---------------------------------------------------------------------------------------------- the invite code -- */

.hg-codecard {
    margin: 8px 0 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 209, 102, 0.08);
    border: 1px solid rgba(255, 209, 102, 0.4);
}

.hg-codecard__title {
    margin: 0 0 8px;
    font-weight: 600;
}

.hg-codecard__title i {
    margin-right: 6px;
    color: var(--hg-accent);
}

.hg-codecard__row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.hg-codecard__value {
    display: block;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--hg-bg);
    border: 1px solid var(--hg-border);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 20px;
    letter-spacing: 0.08em;
    color: var(--hg-accent);
    user-select: all;
    overflow-wrap: anywhere;
}

.hg-codecard__value--link {
    font-size: 12px;
    letter-spacing: 0;
    color: var(--hg-text);
}

.hg-codecard__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.hg-codecard__actions .hg-button {
    flex: 1 1 110px;
    width: auto;
}

.hg-codecard__status {
    margin: 4px 0;
    font-size: 12px;
    color: #bfe6ba;
}

/* ---------------------------------------------------------------------------------------------- Sharing panel -- */

.hg-sharing {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hg-sharing__coderow {
    display: flex;
    gap: 6px;
    align-items: stretch;
    margin: 6px 0;
}

.hg-sharing__coderow .hg-input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}

.hg-sharing__coderow .hg-button {
    flex: 0 0 auto;
    width: auto;
    min-width: 72px;
}

.hg-sharing__two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.hg-sharing .hg-field {
    margin-bottom: 4px;
}

.hg-segments {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin: 4px 0 6px;
}

.hg-segment {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    background: var(--hg-bg-panel-alt);
    border: 1px solid var(--hg-border-control);
    border-radius: 6px;
    color: var(--hg-text-dim);
    font-family: inherit;
    font-size: var(--hg-fs-11);
    line-height: 1.15;
    cursor: pointer;
}

.hg-segment--active {
    background: var(--hg-accent);
    border-color: var(--hg-accent);
    color: #1a1a10;
    font-weight: 600;
}

.hg-segment i {
    font-size: 13px;
}

.hg-rows {
    list-style: none;
    margin: 6px 0;
    padding: 0;
}

.hg-rows__item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--hg-border);
}

.hg-rows__main {
    flex: 1 1 140px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.hg-rows__title {
    font-size: 14px;
    overflow-wrap: anywhere;
}

.hg-rows__main small {
    color: var(--hg-text-dim);
    font-size: var(--hg-fs-11);
    overflow-wrap: anywhere;
}

.hg-rows__button {
    flex: 0 0 auto;
    min-width: 72px;
}

.hg-rows__confirm {
    flex: 1 1 100%;
    padding: 8px;
    border-radius: 6px;
    background: var(--hg-bg-panel-alt);
    border: 1px solid var(--hg-border);
    font-size: 13px;
}

.hg-rows__confirm p {
    margin: 0 0 8px;
}

.hg-rows__item--card {
    display: block;
    padding: 0;
    margin-bottom: 8px;
    border: 1px solid var(--hg-border);
    border-radius: 8px;
    background: var(--hg-bg-panel-alt);
}

.hg-rows__head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: none;
    color: var(--hg-text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.hg-rows__head > i {
    flex: 0 0 auto;
    color: var(--hg-accent);
    font-size: 11px;
}

.hg-rows__body {
    padding: 4px 10px 10px;
    border-top: 1px solid var(--hg-border);
}

.hg-rows--inner {
    margin: 0 0 6px;
}

.hg-rows--inner .hg-rows__item:last-child {
    border-bottom: none;
}

.hg-rows__body > .hg-button,
.hg-rows__body > .hg-sharing__coderow {
    margin-top: 6px;
}

/* --------------------------------------------------------------------------------------------- join page -- */

.hg-join .hg-join__headline {
    font-size: 18px;
    color: var(--hg-text);
    overflow-wrap: anywhere;
}

.hg-join__actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
}

.hg-join .hg-alert,
.hg-join .hg-okay {
    max-width: 420px;
    text-align: left;
}

/* ---------------------------------------------------------------------------------------- Shared with me -- */

.hg-shared {
    margin-top: 14px;
    padding-top: 6px;
    border-top: 1px solid var(--hg-border);
}

.hg-treebar--shared {
    margin-bottom: 2px;
}

.hg-shared__note {
    margin: 2px 0 6px;
}

.hg-tree--shared .hg-tree__row--shared {
    border-left: 2px solid rgba(158, 197, 255, 0.55);
    border-radius: 2px 6px 6px 2px;
}

.hg-tree--shared .hg-tree__row--owner .hg-tree__name > i {
    color: #9ec5ff;
}

.hg-shared__detail {
    margin-top: 10px;
    border-color: rgba(158, 197, 255, 0.45);
}

/* A shared pin on the map: muted and cooler than my own, so it never passes for mine. */
.hg-pin--shared .hg-pin__head {
    opacity: 0.78;
    border-style: dashed;
    border-color: #9ec5ff;
    filter: saturate(0.7);
}

.hg-pin--shared::after {
    opacity: 0.7;
}

/*
 * The panel tabs: seven now. On a phone (or any coarse pointer) the heading takes a line to itself and the tabs share the line under it,
 * each 44 px tall, so a thumb can hit them (seven in one row with the heading did not fit).
 */
@media (max-width: 640px), (pointer: coarse) {
    .hg-panel__header--split {
        flex-wrap: wrap;
    }

    .hg-panel__header--split h2 {
        flex: 1 1 100%;
    }

    .hg-panel__header--split .hg-tabrow {
        flex: 1 1 100%;
        gap: 2px;
    }

    .hg-panel__header--split .hg-tab {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        height: 44px;
        font-size: 14px;
    }

    /* Shared with me: rows and their buttons are big enough to touch. */
    .hg-tree--shared .hg-tree__row {
        min-height: 44px;
    }

    .hg-tree--shared .hg-tree__chev,
    .hg-tree--shared .hg-tree__eye {
        width: 44px;
        height: 44px;
        font-size: 14px;
    }

    .hg-tree--shared .hg-tree__name {
        min-height: 44px;
    }

    .hg-shared__detail .hg-editor__close {
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
    }

    .hg-shared__detail .hg-editor__title {
        align-items: center;
    }
}
