/* The confirm dialog (Components/ConfirmDialog.razor), in the island's material and theme (--app-island-* in
   app-ui.css). On tablets and computers it opens out of the island's place at the top of the page (--app-island-top,
   written by js/app-island.js) over a dimmed page: its outline grows from the island's pill. On phones it is a bottom
   sheet near the thumb (js/app-sheet.js drags it). Its buttons share the width equally, with the island's light, even
   shadow. The app-dlg-* blocks at the end are for the dialog's ChildContent. */

.app-dlg {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--app-island-top, 14px) 24px 24px;
    font-family: var(--app-font-family);
}

/* The page behind an open dialog does not scroll */
html:has(.app-dlg) {
    overflow: hidden;
}

.app-dlg-scrim {
    position: absolute;
    inset: 0;
    background: var(--app-island-scrim);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    animation: app-dlg-fade 0.22s both;
}

.app-dlg-card {
    position: relative;
    width: 440px;
    max-width: 100%;
    max-height: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    /* The platform scrollbar (12px, app-ui.css) has its room kept whether or not a long dialog scrolls, so the right
       padding less that room keeps both sides 22px; touch screens keep no room (below) */
    scrollbar-gutter: stable;
    padding: 22px 10px 22px 22px;
    border-radius: 28px;
    background: var(--app-island-bg);
    color: var(--app-island-text);
    filter: var(--app-island-shadow);
    animation: app-dlg-drop 0.6s cubic-bezier(0.32, 1.2, 0.5, 1) both;
}

/* The same soft glow at the top as the island */
.app-dlg-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(120% 50% at 50% 0%, var(--app-island-glow), transparent 60%);
    pointer-events: none;
}

/* The content fades in once the outline has grown round it */
.app-dlg-card > * {
    position: relative;
    animation: app-dlg-fade 0.25s 0.2s both;
}

.app-dlg-card > .app-sheet-close {
    position: absolute;
    animation: none;
}

/* The drag handle only shows on phones, where the dialog is a sheet (more specific than app-sheet.css, which every
   site loads after this file) */
.app-dlg-card > .app-dlg-grab {
    display: none;
}

@keyframes app-dlg-drop {
    from {
        clip-path: inset(0 calc(50% - 18px) calc(100% - 36px) calc(50% - 18px) round 18px);
    }

    to {
        clip-path: inset(0 0 0 0 round 28px);
    }
}

@keyframes app-dlg-fade {
    from {
        opacity: 0;
    }
}

/* Icon circle, then the title and the message, left aligned */
.app-dlg-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.app-dlg-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 22px;
}

.app-dlg-icon .bx,
.app-dlg-list .bx,
.app-dlg-note .bx,
.app-dlg-chip .bx {
    display: block;
    flex: none;
    width: 1em;
    height: 1em;
    line-height: 1;
}

.app-dlg-icon-primary {
    background: var(--app-island-info-bg);
    color: var(--app-island-info);
}

.app-dlg-icon-danger {
    background: var(--app-island-error-bg);
    color: var(--app-island-error);
}

.app-dlg-text {
    flex: 1;
    min-width: 0;
    padding-top: 1px;
}

.app-dlg-title {
    margin: 0;
    color: var(--app-island-strong);
    font-size: 17px;
    font-weight: 600;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.app-dlg-message {
    margin: 5px 0 0;
    color: var(--app-island-muted);
    font-size: 13.5px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

/* Extra content lines up with the text, right of the icon */
.app-dlg-body {
    margin: 14px 0 0 56px;
}

/* A small form asked for in the dialog (a new password, an emailed code, a photo to adjust): it takes the card's whole
   width under the head, and its parts (fields, notes, lists) stand 16px apart. Fields use the platform's .app-field. */
.app-dlg-body:has(> .app-dlg-form) {
    margin-left: 0;
}

.app-dlg-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 0;
}

/* ---------- buttons ----------
   The platform's own buttons (app-btn, app-btn-wrap) in the middle 42px size: Cancel is the soft button, the action the
   brand gradient (red for a danger tone), a third choice words only. Two share the row equally and stay the same
   width and height; a label longer than its half wraps inside its button instead of being cut. */

.app-dlg-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}

.app-dlg-btn {
    --app-btn-h: 42px;
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    padding-right: 18px;
    padding-left: 18px;
    font-size: 15px;
}

.app-dlg-btn > span {
    min-width: 0;
}

/* The third choice, such as "Reload page": as wide as its words */
.app-dlg-btn-third {
    flex: 0 0 auto;
}

/* Opened with a mouse or a finger, the focus on Cancel shows no ring until the user starts using the keyboard
   (js/app-island.js keeps <html data-app-input>) */
html[data-app-input="pointer"] .app-dlg-btn:focus-visible {
    outline: none;
}

/* ---------- shared content for ChildContent ---------- */

/* A short label above a list */
.app-dlg-label {
    margin: 0 0 8px;
    color: var(--app-island-muted);
    font-size: 12.5px;
}

/* A list of items, such as the menu items that go too or the problems found: one row each with its icon */
.app-dlg-list {
    margin: 0;
    padding: 4px 14px;
    border-radius: 14px;
    background: var(--app-island-hover);
    font-size: 13px;
    list-style: none;
}

.app-dlg-list > li,
.app-dlg-list > p {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 9px 0;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.app-dlg-list > li + li,
.app-dlg-list > p + p {
    border-top: 1px solid var(--app-island-line);
}

.app-dlg-list .bx {
    font-size: 17px;
}

.app-dlg-list-error {
    color: var(--app-island-error);
}

.app-dlg-list-menu {
    color: var(--app-island-info);
}

/* How two things change, such as the two pages of "Set as home page": a name, then a chip, an arrow and a chip */
.app-dlg-swap {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--app-island-hover);
    font-size: 13.5px;
}

.app-dlg-swap > b {
    min-width: 0;
    overflow: hidden;
    color: var(--app-island-strong);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-dlg-swap > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.app-dlg-swap-arrow {
    color: var(--app-island-muted);
    font-size: 16px;
}

.app-dlg-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    background: var(--app-island-line);
    color: var(--app-island-text);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.app-dlg-chip .bx {
    font-size: 14px;
}

.app-dlg-chip-live {
    background: var(--app-island-ok-bg);
    color: var(--app-island-ok);
}

/* A note to read before confirming: amber, or purple (app-dlg-note-info) when it only informs */
.app-dlg-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 11px 14px;
    border-radius: 14px;
    background: var(--app-island-warn-bg);
    color: var(--app-island-text);
    font-size: 13px;
    line-height: 1.55;
}

.app-dlg-note .bx {
    margin-top: 1px;
    color: var(--app-island-warn);
    font-size: 18px;
}

.app-dlg-note-info {
    background: var(--app-island-info-bg);
}

.app-dlg-note-info .bx {
    color: var(--app-island-info);
}

.app-dlg-note + .app-dlg-note,
.app-dlg-list + .app-dlg-note,
.app-dlg-note + .app-dlg-list {
    margin-top: 10px;
}

/* A choice that goes with the action, such as "Also restore the header and footer" */
.app-dlg-check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    color: var(--app-island-text);
    font-size: 13px;
    cursor: pointer;
}

.app-dlg-check input {
    flex: none;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--app-island-primary);
}

/* A check still running before the action can be confirmed */
.app-dlg-busy {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--app-island-muted);
    font-size: 13px;
}

.app-dlg-busy::before {
    content: "";
    flex: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--app-island-track);
    border-top-color: var(--app-island-progress);
    border-radius: 50%;
    animation: app-dlg-spin 0.9s linear infinite;
}

/* ---------- phones: a bottom sheet near the thumb ---------- */

/* Keys and what they do (a list of keyboard shortcuts): the keys right-aligned in the first column */
.app-dlg-keys {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px 16px;
    margin: 0;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--app-island-hover);
    font-size: 13.5px;
}

.app-dlg-keys dt {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}

.app-dlg-keys dd {
    margin: 0;
    color: var(--app-island-text);
}

.app-dlg-keys kbd {
    display: inline-grid;
    place-items: center;
    box-sizing: border-box;
    min-width: 26px;
    height: 26px;
    padding: 0 7px;
    border: 1px solid var(--app-island-line);
    border-bottom-width: 2px;
    border-radius: 7px;
    background: var(--app-island-bg);
    color: var(--app-island-strong);
    font: 600 12px var(--app-font-family);
}

@media (max-width: 767.98px) {
    .app-dlg {
        align-items: flex-end;
        padding: 0;
    }

    .app-dlg-card {
        width: 100%;
        max-height: 70vh;
        max-height: 70dvh;
        padding: 0 4px calc(20px + env(safe-area-inset-bottom, 0px)) 16px;
        border-radius: 26px 26px 0 0;
        touch-action: pan-y;
        /* Only before it starts (backwards), so the drag of js/app-sheet.js takes over once it is in place */
        animation: app-dlg-up 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    }

    .app-dlg-card.app-sheet-full {
        max-height: 94vh;
        max-height: 94dvh;
    }

    .app-dlg-card > * {
        animation: none;
    }

    /* The handle lies on the dialog's own glass, not on a band of the sheet colour */
    /* The handle reaches both edges of the sheet: on the right only up to the scrollbar's room, so 12px on its left
       puts its bar back on the sheet's centre */
    .app-dlg-card > .app-dlg-grab {
        display: flex;
        margin: 0 -4px 8px -16px;
        padding-left: 12px;
        --app-sheet-grab-bg: transparent;
    }

    .app-dlg-body {
        margin-left: 0;
    }

    /* The buttons stack, the action on top, each across the sheet */
    .app-dlg-actions {
        flex-direction: column-reverse;
    }

    .app-dlg-btn {
        flex: none;
        width: 100%;
    }
}

/* Touch screens draw their scrollbar over the content and keep no room for it, so both sides keep their padding */
@media (hover: none) {
    .app-dlg-card {
        scrollbar-gutter: auto;
        padding-right: 22px;
    }
}

@media (hover: none) and (max-width: 767.98px) {
    .app-dlg-card {
        padding-right: 16px;
    }

    .app-dlg-card > .app-dlg-grab {
        margin-right: -16px;
        padding-left: 0;
    }
}

@keyframes app-dlg-up {
    from {
        transform: translateY(100%);
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-dlg-card,
    .app-dlg-card > * {
        animation: app-dlg-fade 0.2s both;
    }

    .app-dlg-busy::before {
        animation-duration: 2s;
    }
}
