/*
 * The Save button's look: one outlined box with rounded corners, with a sheen across Save while saving, and Solid's
 * logo, shaded, in Solid purple, on the Pod's screens.
 *
 * Every rule starts from `.solid-save-button`, so it outweighs the page's own rules for buttons, inputs and labels,
 * which would otherwise reach inside. Its colours, font, sizes and shape are its own, set below as custom properties:
 * an app themes the button by setting them on its container, with a selector that outweighs `.solid-save-button`, such
 * as its ID. The defaults draw the outlined box; an app can instead draw it to suit a toolbar, as a pill on a dark bar.
 */

.solid-save-button {
    --ssb-paper: #ffffff;
    --ssb-surface: #f6f5f1;
    --ssb-ink: #1f1d1a;
    --ssb-muted: #67645e;
    --ssb-line: #dcd8cf;
    /* The button's outline. */
    --ssb-outline: #8f8b83;
    /* Where saves go with no Pod: ink on a pale ground. */
    --ssb-local: #1f1d1a;
    --ssb-local-soft: #f1efe8;
    --ssb-button: #1f1d1a;
    --ssb-button-text: #ffffff;
    --ssb-pod: #6a3fe0;
    --ssb-pod-soft: #ece6ff;
    --ssb-error: #b42318;
    --ssb-error-soft: #fbe6e4;
    --ssb-shadow: 0 10px 30px rgb(31 29 26 / 0.16), 0 1px 3px rgb(31 29 26 / 0.12);
    --ssb-font: system-ui, sans-serif;
    /* Text: the size of Save, and of the panel's text, which the panel's other text and icons scale with */
    --ssb-font-size: 1.05rem;
    --ssb-panel-font-size: 0.88rem;
    --ssb-font-weight: 400;
    /* The button's shape: its height, corners, outline, the line between its halves, and its background */
    --ssb-height: 2.4rem;
    --ssb-radius: 12px;
    --ssb-border: 1px solid var(--ssb-outline);
    --ssb-divider: 1px solid var(--ssb-outline);
    --ssb-background: var(--ssb-paper);
    /* What's under the pointer: Save's background, and a shade laid over the right half's */
    --ssb-hover: var(--ssb-surface);
    --ssb-where-hover: transparent;
    /* The sheen that runs across Save while saving */
    --ssb-sweep: rgb(31 29 26 / 0.08);
    /* The right half's chevron: an image whose shape is drawn in the right half's colour, its size, and the gap before it */
    --ssb-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
    --ssb-chevron-size: 0.95em;
    --ssb-chevron-gap: 0.15rem;
    /* The panel: how far below the button, its width and corners, and Solid's colour in it, which may differ from the
       right half's when the panel's background is dark */
    --ssb-panel-offset: 0.5rem;
    --ssb-panel-width: min(21rem, calc(100vw - 2rem));
    --ssb-panel-radius: 12px;
    --ssb-panel-pod: var(--ssb-pod);
    display: grid;
    justify-items: end;
    font-family: var(--ssb-font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ssb-ink);
}

/* One weight throughout, whatever the page sets for its own buttons and labels, and paragraphs in the panel's size, not
   the page's. */
.solid-save-button * { font-weight: var(--ssb-font-weight); }
.solid-save-button p { font-size: inherit; line-height: inherit; }

/* Icons */
.solid-save-button .ssb-icon {
    width: 1.2em; height: 1.2em; flex: none; display: block;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.solid-save-button .ssb-icon--pod { stroke: none; }

/* A button's words, trimmed to the top of their capitals and their baseline, so that it's the letters that are centred
   between the button's edges and beside its icon, not the font's line box. Fonts such as Helvetica Neue leave more
   room above their letters than below, which would put the words a pixel or two high. A browser without text-box shows
   them as before, and each button keeps the height it had either way. */
.solid-save-button .ssb-label { text-box: trim-both cap alphabetic; }
.solid-save-button .ssb-icon--spin { animation: ssb-spin 0.9s linear infinite; }
@keyframes ssb-spin { to { transform: rotate(360deg); } }

/* The split button: one outlined box with rounded corners, with a line between its halves. */
.solid-save-button .ssb-anchor { position: relative; display: inline-block; }
.solid-save-button .ssb-split {
    display: inline-flex; border: var(--ssb-border); border-radius: var(--ssb-radius); overflow: hidden;
    background: var(--ssb-background);
}
.solid-save-button .ssb-split__save {
    font-family: var(--ssb-font); font-size: var(--ssb-font-size); line-height: 1.2;
    display: inline-flex; align-items: center; gap: 0.45rem;
    background: transparent; color: var(--ssb-ink); border: 0; border-radius: 0;
    padding: 0 1rem 0 0.95rem; min-height: var(--ssb-height); margin: 0;
    cursor: pointer; position: relative; overflow: hidden; opacity: 1;
}
.solid-save-button .ssb-split__save:hover { background: var(--ssb-hover); }
.solid-save-button .ssb-split__save:disabled { cursor: progress; background: transparent; }
.solid-save-button .ssb-split__slot,
.solid-save-button .ssb-split__slot .ssb-icon { width: var(--ssb-icon-size, 1.2em); height: var(--ssb-icon-size, 1.2em); }
.solid-save-button .ssb-split__slot { display: inline-grid; place-items: center; flex: none; }
/* While saving, a sheen runs across the Save half, as well as the spinner. */
.solid-save-button .ssb-split__save--sweep::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(100deg, transparent 0 35%, var(--ssb-sweep) 50%, transparent 65% 100%);
    background-size: 250% 100%; animation: ssb-sweep 1s linear infinite;
}
@keyframes ssb-sweep { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.solid-save-button .ssb-split__where {
    font: inherit; display: inline-flex; align-items: center; gap: var(--ssb-chevron-gap); margin: 0;
    border: 0; border-left: var(--ssb-divider); border-radius: 0;
    padding: 0 0.75rem 0 0.6rem; min-height: var(--ssb-height); cursor: pointer;
    background-color: var(--ssb-local-soft); color: var(--ssb-local);
}
.solid-save-button .ssb-split__where:hover {
    background-image: linear-gradient(var(--ssb-where-hover), var(--ssb-where-hover));
}
.solid-save-button .ssb-split__chevron {
    display: block; flex: none; width: var(--ssb-chevron-size); height: var(--ssb-chevron-size); background: currentColor;
    -webkit-mask: var(--ssb-chevron) center / contain no-repeat; mask: var(--ssb-chevron) center / contain no-repeat;
}
.solid-save-button .ssb-split__where--pod { background-color: var(--ssb-pod-soft); color: var(--ssb-pod); }
.solid-save-button .ssb-split__where--failed { background-color: var(--ssb-error-soft); color: var(--ssb-error); }
.solid-save-button .ssb-split__where-icon { position: relative; display: inline-grid; place-items: center; }
.solid-save-button .ssb-split__where-icon .ssb-icon { width: var(--ssb-icon-size, 1.3rem); height: var(--ssb-icon-size, 1.3rem); }
.solid-save-button .ssb-split__badge {
    position: absolute; right: -3px; top: -3px; width: 0.55rem; height: 0.55rem; border-radius: 50%;
    background: var(--ssb-error); border: 2px solid var(--ssb-paper);
}
/* The box clips anything outside it, so a focused half is ringed inside its edge. */
.solid-save-button .ssb-split button:focus-visible { outline: 2px solid var(--ssb-outline); outline-offset: -4px; box-shadow: none; }
/* The ring's corners follow the box's, just inside them. */
.solid-save-button .ssb-split__save:focus-visible { border-radius: max(0px, var(--ssb-radius) - 3px) 0 0 max(0px, var(--ssb-radius) - 3px); }
.solid-save-button .ssb-split__where:focus-visible { border-radius: 0 max(0px, var(--ssb-radius) - 3px) max(0px, var(--ssb-radius) - 3px) 0; }
/* Focus in the panel is ringed with a grey line next to the edge and the ground of the browser's half outside it, or in
   Solid's purple on the Pod's screens. */
.solid-save-button .ssb-panel button:focus-visible,
.solid-save-button .ssb-panel a:focus-visible {
    outline: 2px solid var(--ssb-outline); outline-offset: 0; box-shadow: 0 0 0 5px var(--ssb-local-soft);
}
.solid-save-button .ssb-panel--pod button:focus-visible,
.solid-save-button .ssb-panel--pod a:focus-visible { outline: 3px solid var(--ssb-panel-pod); outline-offset: 2px; box-shadow: none; }

/* What the Pod icon does when a save lands (pulse), or fails (buzz). */
.solid-save-button .ssb-anim--saved { animation: ssb-pulse 0.45s ease-out; }
.solid-save-button .ssb-anim--failed { animation: ssb-buzz 0.4s linear; }
@keyframes ssb-pulse { 0% { transform: none; } 40% { transform: scale(1.2); } 100% { transform: none; } }
@keyframes ssb-buzz {
    0%, 100% { transform: none; }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-1.5px); }
    20%, 40%, 60%, 80% { transform: translateX(1.5px); }
}
@keyframes ssb-glow {
    0% { filter: none; }
    30% { filter: drop-shadow(0 0 5px currentColor) brightness(1.25); }
    100% { filter: none; }
}
@keyframes ssb-blink { 0%, 40%, 80% { opacity: 1; } 20%, 60% { opacity: 0.15; } }

/* The panel, under the button and lined up with its right-hand edge */
.solid-save-button .ssb-panel {
    position: absolute; top: calc(100% + var(--ssb-panel-offset)); right: 0; z-index: 3;
    width: var(--ssb-panel-width); box-sizing: border-box;
    background: var(--ssb-paper); color: var(--ssb-ink); border: 1px solid var(--ssb-line); border-radius: var(--ssb-panel-radius);
    box-shadow: var(--ssb-shadow); padding: 1rem; display: grid; gap: 0.6rem; text-align: left;
    font-size: var(--ssb-panel-font-size);
    /* 1rem at the panel's default text size, so its other text and its icons scale with the size an app sets */
    --ssb-panel-rem: calc(var(--ssb-panel-font-size) / 0.88);
}
/* An empty strip under the panel, so a page scrolled to the panel's end leaves a little room below it */
.solid-save-button .ssb-panel::after {
    content: ""; position: absolute; top: 100%; left: 0; width: 1px; height: 1.5rem; pointer-events: none;
}
.solid-save-button .ssb-panel p { margin: 0; }
/* While the panel waits, as its corner spins, so does the pointer over it: Disconnect's menu has gone from under it. */
.solid-save-button .ssb-panel[aria-busy="true"] { cursor: progress; }
/* The panel's corner: a spinner while it waits, or a tick once saved. In ink, or in Solid's purple on the Pod's screens. */
.solid-save-button .ssb-panel__corner { position: absolute; top: 1.05rem; right: 1rem; display: flex; color: var(--ssb-ink); }
.solid-save-button .ssb-panel--pod .ssb-panel__corner { color: var(--ssb-panel-pod); }
.solid-save-button .ssb-panel__corner .ssb-icon { width: calc(1.1 * var(--ssb-panel-rem)); height: calc(1.1 * var(--ssb-panel-rem)); }
.solid-save-button .ssb-panel__heading { display: flex; gap: 0.5rem; align-items: center; font-size: calc(1.05 * var(--ssb-panel-rem)); }
.solid-save-button .ssb-panel--corner .ssb-panel__heading { padding-right: 1.6rem; }
.solid-save-button .ssb-panel__heading--pod { color: var(--ssb-panel-pod); }
.solid-save-button .ssb-panel__heading--local { color: var(--ssb-local); }
.solid-save-button .ssb-panel__sub { color: var(--ssb-muted); }
.solid-save-button .ssb-panel__host {
    display: flex; gap: 0.4rem; align-items: center; justify-content: space-between;
    font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: calc(0.8 * var(--ssb-panel-rem));
    background: var(--ssb-surface); border-radius: 6px; padding: 0.3rem 0.5rem;
}
.solid-save-button .ssb-panel__host span { min-width: 0; overflow-wrap: anywhere; }
.solid-save-button .ssb-panel__open { color: var(--ssb-muted); display: grid; place-items: center; padding: 0.15rem; border-radius: 4px; }
.solid-save-button .ssb-panel__open:hover { color: var(--ssb-panel-pod); }
.solid-save-button .ssb-panel__open .ssb-icon { width: var(--ssb-panel-rem); height: var(--ssb-panel-rem); }
.solid-save-button .ssb-panel__tools { display: flex; gap: 0.1rem; align-items: center; flex: none; }
/* "More", beside "Open my Pod": as quiet, so Disconnect, rarely wanted, is out of sight in its menu */
.solid-save-button .ssb-more { position: relative; display: flex; }
.solid-save-button .ssb-panel__more {
    font: inherit; margin: 0; border: 0; background: transparent; cursor: pointer;
    color: var(--ssb-muted); display: grid; place-items: center; padding: 0.15rem; border-radius: 4px;
}
.solid-save-button .ssb-panel__more:hover,
.solid-save-button .ssb-panel__more[aria-expanded="true"] { color: var(--ssb-panel-pod); }
.solid-save-button .ssb-panel__more .ssb-icon { width: var(--ssb-panel-rem); height: var(--ssb-panel-rem); }
.solid-save-button .ssb-panel__actions--end { justify-content: flex-end; }
.solid-save-button .ssb-menu {
    position: absolute; top: calc(100% + 0.35rem); right: -0.35rem; z-index: 1;
    background: var(--ssb-paper); border: 1px solid var(--ssb-line); border-radius: 8px; box-shadow: var(--ssb-shadow);
    padding: 0.25rem; font-family: var(--ssb-font); font-size: var(--ssb-panel-font-size);
}
.solid-save-button .ssb-menu__item {
    font: inherit; margin: 0; border: 0; background: transparent; color: var(--ssb-ink); cursor: pointer;
    display: flex; gap: 0.5rem; align-items: center; white-space: nowrap; padding: 0.35rem 0.6rem; border-radius: 6px;
    min-height: calc(1lh + 0.7rem);
}
.solid-save-button .ssb-menu__item:hover { background: var(--ssb-surface); }
.solid-save-button .ssb-menu__item .ssb-icon { width: var(--ssb-panel-rem); height: var(--ssb-panel-rem); }
.solid-save-button .ssb-panel__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.solid-save-button .ssb-panel__foot { font-size: calc(0.8 * var(--ssb-panel-rem)); color: var(--ssb-muted); display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.solid-save-button .ssb-panel__foot a { color: var(--ssb-ink); }
.solid-save-button .ssb-panel button:disabled { cursor: progress; opacity: 0.6; }

/* Buttons in the panel */
.solid-save-button .ssb-button {
    font: inherit; line-height: 1.4; border-radius: 8px; padding: 0.35rem 0.85rem; margin: 0;
    min-height: calc(1lh + 0.7rem + 2px);
    cursor: pointer; border: 1px solid var(--ssb-line); background: var(--ssb-surface); color: var(--ssb-ink);
    display: inline-flex; gap: 0.5rem; align-items: center;
}
.solid-save-button .ssb-button--primary { background: var(--ssb-button); color: var(--ssb-button-text); border-color: var(--ssb-button); }
/* An icon at the start of a button sits a little nearer its edge than the words do at the other end, as the logo's
   hexagon reads as further in than its box. The words stay where they were. */
.solid-save-button .ssb-button > .ssb-icon:first-child { margin-left: -0.25em; margin-right: 0.25em; }

/* A failure, with a button to try again if there's one */
.solid-save-button .ssb-failbox {
    border: 1px solid var(--ssb-error); background: var(--ssb-error-soft);
    color: var(--ssb-error); border-radius: 10px; padding: 0.6rem 0.7rem;
}
.solid-save-button .ssb-failbox p { display: flex; gap: 0.45rem; align-items: flex-start; overflow-wrap: anywhere; }
.solid-save-button .ssb-failbox p .ssb-icon { width: var(--ssb-panel-rem); height: var(--ssb-panel-rem); margin-top: 0.15rem; }

/* The WebID form */
.solid-save-button .ssb-webid { display: grid; gap: 0.3rem; }
.solid-save-button .ssb-webid label {
    display: block; margin: 0; font-size: calc(0.82 * var(--ssb-panel-rem)); color: var(--ssb-muted); cursor: default;
}
.solid-save-button .ssb-webid__row { display: flex; gap: 0.4rem; }
.solid-save-button .ssb-webid input {
    font: inherit; font-size: calc(0.85 * var(--ssb-panel-rem)); min-width: 0; flex: 1; margin: 0;
    border: 1px solid var(--ssb-line); border-radius: 8px; padding: 0.4rem 0.55rem;
    background: var(--ssb-paper); color: var(--ssb-ink); box-shadow: none;
}
.solid-save-button .ssb-webid input:focus-visible { outline: 3px solid var(--ssb-panel-pod); outline-offset: 1px; border-color: var(--ssb-line); }
.solid-save-button .ssb-webid input[aria-invalid="true"] { border-color: var(--ssb-error); }
/* A WebID that's wrong is ringed in the red of the box that says why, not the Pod's purple. */
.solid-save-button .ssb-webid input[aria-invalid="true"]:focus-visible { outline-color: var(--ssb-error); }
.solid-save-button .ssb-webid--working input { color: var(--ssb-muted); }

.solid-save-button .ssb-visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    .solid-save-button .ssb-icon--spin,
    .solid-save-button .ssb-split__save--sweep::after { animation: none; }
    /* The pulse becomes a glow, and the buzz a blink, which don't move. */
    .solid-save-button .ssb-anim--saved { animation: ssb-glow 0.9s ease-out; }
    .solid-save-button .ssb-anim--failed { animation: ssb-blink 0.7s steps(1, end); }
}
