:root {
    --pico-font-size: 100%;
    --z-brand: #2e7d5b;
    --z-on-brand: #fff;
    --z-page: #f2f5f3;
    --z-card: #fff;
    --z-text: #1d2a23;
    --z-badge-bg: #e8ece9;
    --z-badge-fg: #1d2a23;
    --z-badge-active-bg: #d7f0e3;
    --z-badge-active-fg: #1d1d1d;
    --z-badge-pending-bg: #fff1c2;
    --z-badge-pending-fg: #1d1d1d;
    --z-badge-closed-bg: #e4e4e4;
    --z-badge-closed-fg: #555;
    --z-card-hover-shadow: 0 2px 10px rgb(0 0 0 / 0.18);
    --z-toast-bg: #222;
    --z-toast-fg: #fff;
    --z-overlay: rgb(255 255 255 / 0.85);
    background-color: var(--z-page);
}

@media (prefers-color-scheme: dark) {
    :root {
        --z-brand: #1f5a41;
        --z-on-brand: #e8f3ec;
        --z-page: #13171f;
        --z-card: #1c222b;
        --z-text: #dfe3e8;
        --z-badge-bg: #2a3140;
        --z-badge-fg: #dfe3e8;
        --z-badge-active-bg: #1f4a36;
        --z-badge-active-fg: #d7f0e3;
        --z-badge-pending-bg: #4a3f12;
        --z-badge-pending-fg: #fff1c2;
        --z-badge-closed-bg: #2f343c;
        --z-badge-closed-fg: #b8bec8;
        /* a dark drop shadow is invisible on the near-black page, so lift the card with a light glow instead */
        --z-card-hover-shadow: 0 2px 10px rgb(255 255 255 / 0.1);
        --z-toast-bg: #e8ecef;
        --z-toast-fg: #13171f;
        --z-overlay: rgb(19 23 31 / 0.85);
    }
}

article {
    background-color: var(--z-card);
}

[x-cloak] {
    display: none !important;
}

body {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
}

main.container {
    padding-top: 1rem;
}

.narrow {
    max-width: 24rem;
    margin: 3rem auto;
}

.appbar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--z-brand);
    color: var(--z-on-brand);
}

.brand {
    font-size: 1.15rem;
    font-weight: 700;
}

.appnav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 10;
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--z-card);
    border-top: 1px solid var(--pico-muted-border-color);
}

.appnav > a {
    flex: 1;
    padding: 0.9rem 0;
    text-align: center;
    text-decoration: none;
    color: var(--pico-muted-color);
}

.appnav > a.active {
    color: var(--pico-primary);
    font-weight: 600;
}

/* on a phone the FAB adds an item and the brand is in the appbar */
.appnav .brand,
.appnav .nav-add {
    display: none;
}

/* `:not([role])` matches Pico's own selector specificity, otherwise its form-element defaults (grey
   text on a near-white box, and a solid background while focused/open) win over these */
.space-switcher details.dropdown > summary:not([role]) {
    color: var(--z-on-brand);
    font-weight: 600;
    background: transparent;
    border-color: rgb(255 255 255 / 0.5);
}

/* Pico's focus ring is primary-coloured, invisible on the brand colour */
.space-switcher details.dropdown > summary:not([role]):focus-visible {
    box-shadow: 0 0 0 var(--pico-outline-width) var(--z-on-brand);
}

/* inside <nav>, Pico's own dropdown focus-visible rule has an extra `nav` ancestor and outranks the one above */
.appnav .space-switcher details.dropdown > summary:not([role]):focus-visible {
    box-shadow: 0 0 0 var(--pico-outline-width) var(--z-on-brand);
}

/* the menu has Pico's dropdown background: normal text colours, not the brand bar's */
.space-switcher details.dropdown > ul a {
    color: var(--pico-dropdown-color);
}

/* the switcher sits at the right of the app bar; Pico's own `left: 0` grows the menu off the right edge.
   `width: max-content` + `max-width` keep a space name longer than the screen from overflowing the other
   side too, without `min-width: fit-content` collapsing the box to its longest single word first. */
.appbar .space-switcher details.dropdown > summary + ul {
    left: auto;
    right: 0;
    width: max-content;
    min-width: 0;
    max-width: calc(100vw - 2rem);
    white-space: normal;
}

/* Pico's `min-width: fit-content` can be wider than the 200px sidebar, which then clips it horizontally
   (an `overflow-y` other than visible makes the browser clip `overflow-x` too) */
.appnav .space-switcher details.dropdown > summary + ul {
    min-width: 0;
    white-space: normal;
}

.space-switcher a[aria-current="true"] {
    font-weight: 600;
}

.space-switcher .menu-separator {
    border-top: 1px solid var(--pico-muted-border-color);
}

.space-switcher .space-row {
    display: flex;
}

/* Pico's negative margins make each link fill the row; the two links here must not overlap */
.space-switcher .space-row > a:first-child {
    flex: 1;
    min-width: 0;
    margin-right: 0;
}

.space-switcher .space-row > .space-gear {
    flex: none;
    margin-left: 0;
    color: var(--pico-muted-color);
}

/* on a phone the switcher is in the appbar */
.appnav .space-switcher {
    display: none;
}

.fab {
    position: fixed;
    right: 1.25rem;
    bottom: calc(5.5rem + env(safe-area-inset-bottom));
    z-index: 11;
    display: grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    font-size: 2rem;
    text-decoration: none;
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}

.chips {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    overflow-x: auto;
}

/* role="group" is there for screen readers; Pico would otherwise turn it into a joined button group */
.chips[role=group] {
    width: auto;
    box-shadow: none;
}

.chips[role=group] > .chip {
    flex: none;
    width: auto;
    margin: 0;
    padding: 0.35rem 0.8rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* not var(--pico-color): inside a button Pico sets it to the button's own (white) text colour */
.chip:not(.active) {
    background: transparent;
    color: var(--pico-secondary);
    border-color: var(--pico-muted-border-color);
}

.item-grid,
.gallery,
.plain-list {
    margin: 0 0 1rem;
    padding: 0;
}

.item-grid li,
.gallery li,
.plain-list li {
    list-style: none;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.item-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    border-radius: var(--pico-border-radius);
    background: var(--z-card);
    box-shadow: var(--pico-card-box-shadow);
    color: var(--z-text);
    text-decoration: none;
}

.item-card:hover {
    box-shadow: var(--z-card-hover-shadow);
}

/* Pico's default focus-visible box-shadow loses to .item-card's own box-shadow at equal specificity */
.item-card:focus-visible {
    outline: var(--pico-outline-width) solid var(--pico-primary-focus);
    outline-offset: 2px;
}

.item-card img,
.thumb-placeholder {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.thumb-placeholder {
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    background: var(--z-page);
    color: var(--pico-muted-color);
}

.thumb-placeholder::after {
    content: "brak zdjęcia";
}

.item-card-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    padding: 0.5rem 0.6rem 0.6rem;
}

.item-name {
    display: -webkit-box;
    overflow: hidden;
    font-weight: 600;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.item-price {
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 0.6rem;
    font-size: 0.75rem;
    background: var(--z-badge-bg);
    color: var(--z-badge-fg);
}

.badge[data-status="listed"],
.badge[data-status="published"] {
    background: var(--z-badge-active-bg);
    color: var(--z-badge-active-fg);
}

.badge[data-status="ready"],
.badge[data-status="draft"] {
    background: var(--z-badge-pending-bg);
    color: var(--z-badge-pending-fg);
}

.badge[data-status="sold"],
.badge[data-status="given_away"],
.badge[data-status="discarded"],
.badge[data-status="expired"],
.badge[data-status="removed"] {
    background: var(--z-badge-closed-bg);
    color: var(--z-badge-closed-fg);
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 0.5rem;
}

.gallery li {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 0.4rem;
    background: var(--pico-muted-border-color);
}

.gallery img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery li[data-status="error"],
.gallery li[data-status="failed"] {
    outline: 2px solid var(--pico-del-color);
}

.gallery small {
    position: absolute;
    inset: 0;
    padding: 0.3rem;
    font-size: 0.7rem;
    background: var(--z-overlay);
    color: var(--pico-del-color);
}

.gallery .tools {
    position: absolute;
    inset: auto 0 0 0;
    display: flex;
    justify-content: space-between;
}

.gallery .tools button {
    width: auto;
    margin: 0;
    padding: 0.1rem 0.45rem;
    font-size: 0.9rem;
}

.photo-pick {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
}

/* Pico's default focus ring is an outer box-shadow, clipped by .gallery li's overflow: hidden */
.photo-pick:focus-visible {
    box-shadow: inset 0 0 0 2px var(--z-card), inset 0 0 0 4px var(--pico-primary-focus);
}

/* only the desktop layout has room for it; lazy, so phones never download the full photo */
.photo-main {
    display: none;
}

/* touch-action: none keeps a finger drag drawing instead of scrolling the page */
.redact-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    touch-action: none;
    user-select: none;
    cursor: crosshair;
}

.redact-stage img {
    display: block;
    max-width: 100%;
    max-height: 60vh;
}

.redact-mark {
    position: absolute;
    background: #000;
    outline: 2px solid var(--pico-primary);
    pointer-events: none;
}

.row-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.row-buttons > * {
    width: auto;
    margin: 0;
}

.photo-inputs {
    display: flex;
    gap: 0.5rem;
}

.photo-inputs label {
    flex: 1;
}

/*
 * Unlike `hidden`, keeps the input focusable, so the label works as a button from the keyboard.
 * Qualified with the type to outrank Pico's input:not(…) sizing, which otherwise makes the page overflow.
 */
input[type=file].visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

label[role=button]:focus-within {
    outline: var(--pico-outline-width) solid var(--pico-primary-focus);
    outline-offset: 2px;
}

.error {
    color: var(--pico-del-color);
}

.muted {
    color: var(--pico-muted-color);
}

.counter {
    margin-right: 0.75rem;
    font-size: 0.8rem;
}

.counter.over {
    color: var(--pico-del-color);
    font-weight: 600;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.tile {
    margin: 0;
    text-align: left;
    border: 0;
    background: var(--z-card);
    box-shadow: var(--pico-card-box-shadow);
    /* not var(--pico-color): inside a button Pico sets it to the button's own colour */
    color: var(--z-text);
}

.tile strong {
    display: block;
    font-size: 1.6rem;
    color: var(--pico-primary);
}

/* Pico's focus ring is drawn via --pico-box-shadow, which .tile's literal box-shadow overrides */
.tile:focus-visible {
    outline: var(--pico-outline-width) solid var(--pico-primary-focus);
    outline-offset: 2px;
}

.tile:hover {
    box-shadow: var(--z-card-hover-shadow);
}

.page-card {
    padding: var(--pico-block-spacing-vertical) var(--pico-block-spacing-horizontal);
    border-radius: var(--pico-border-radius);
    background: var(--z-card);
    box-shadow: var(--pico-card-box-shadow);
}

/* the materials panel already sits inside a card */
.page-card article {
    margin-inline: 0;
    padding: 0;
    background: none;
    box-shadow: none;
}

/* Pico's article > header uses negative margins sized to the article's own padding, which is 0 here */
.page-card article > header {
    margin: 0 0 var(--pico-spacing);
    padding: 0 0 var(--pico-spacing);
    background: none;
    border: 0;
    border-bottom: var(--pico-border-width) solid var(--pico-card-border-color);
    font-weight: 600;
}

.stale-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.stale-row button {
    width: auto;
    margin: 0;
}

.member-row select {
    width: auto;
    margin: 0;
}

.member-row .row-buttons {
    margin: 0;
}

/* outranks `.page-card article`, which drops the padding */
.page-card .danger-zone {
    padding: var(--pico-spacing);
    border: 1px solid var(--pico-del-color);
    border-radius: var(--pico-border-radius);
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.account-page .page-head p {
    margin: 0;
}

.account-page .page-head button {
    width: auto;
    margin: 0;
}

.account-page details:last-child {
    margin-bottom: 0;
}

.account-page .ok {
    color: var(--pico-ins-color);
}

.token-created {
    margin-block: var(--pico-spacing);
    padding: var(--pico-spacing);
    border: 1px solid var(--pico-primary);
    border-radius: var(--pico-border-radius);
}

.toasts {
    position: fixed;
    right: 1rem;
    /* above the FAB (bottom 5.5rem + 3.5rem tall), so it doesn't cover it */
    bottom: calc(9.25rem + env(safe-area-inset-bottom));
    left: 1rem;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast,
.toast-note {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    text-align: center;
    background: var(--z-toast-bg);
    color: var(--z-toast-fg);
}

/* top, not bottom: the toast and the FAB live down there */
.update-banner {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top));
    right: 1rem;
    left: 1rem;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border-radius: 0.5rem;
    background: var(--z-toast-bg);
    color: var(--z-toast-fg);
}

.update-banner button {
    width: auto;
    margin: 0;
    padding: 0.4rem 1rem;
}

.toast-note {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    text-align: left;
    overflow-wrap: anywhere;
}

.toast-note span {
    flex: 1;
}

.toast-close {
    width: auto;
    margin: 0;
    padding: 0 0.25rem;
    border: 0;
    background: none;
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
}

@media (min-width: 1024px) {
    .update-banner {
        left: auto;
        max-width: 28rem;
    }

    body.signed-in {
        display: grid;
        grid-template-columns: 200px minmax(0, 1fr);
        grid-template-areas: "nav main";
        padding-bottom: 0;
    }

    body.signed-in > main.container {
        grid-area: main;
        width: 100%;
        max-width: 1200px;
        padding-top: 2rem;
    }

    .appbar,
    .fab {
        display: none;
    }

    .appnav {
        grid-area: nav;
        position: sticky;
        inset: 0 auto auto 0;
        flex-direction: column;
        gap: 0.25rem;
        height: 100vh;
        padding: 1.25rem 0.75rem;
        overflow-y: auto;
        background: var(--z-brand);
        border-top: 0;
    }

    .appnav > a {
        flex: none;
        padding: 0.6rem 0.75rem;
        border-radius: var(--pico-border-radius);
        text-align: left;
        color: var(--z-on-brand);
    }

    .appnav > a.active {
        color: var(--z-on-brand);
        background: rgb(255 255 255 / 0.15);
    }

    /* Pico's focus ring for plain links is a primary-coloured box-shadow, invisible on the green sidebar */
    .appnav > a:focus-visible {
        box-shadow: 0 0 0 var(--pico-outline-width) var(--z-on-brand);
    }

    .appnav .brand {
        display: block;
        padding: 0 0.75rem 1rem;
        color: var(--z-on-brand);
    }

    .appnav .space-switcher {
        display: block;
        padding: 0 0.75rem 1rem;
        color: var(--z-on-brand);
    }

    .appnav .space-switcher details {
        width: 100%;
    }

    .appnav .nav-add {
        display: block;
        margin-top: 0.75rem;
        text-align: center;
        font-weight: 600;
        background: var(--z-on-brand);
        color: var(--z-brand);
    }

    /* .appnav > a:focus-visible's box-shadow is --z-on-brand too, invisible against this button's own --z-on-brand background */
    .appnav .nav-add:focus-visible {
        box-shadow: 0 0 0 2px var(--z-brand), 0 0 0 4px var(--z-on-brand);
    }

    .appnav .nav-account {
        margin-top: auto;
    }

    /* no FAB to keep clear of */
    .toasts {
        bottom: 1.5rem;
        left: auto;
        right: 1.5rem;
        min-width: 16rem;
    }

    .item-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .list-tools {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .list-tools .chips {
        margin: 0;
    }

    .list-tools input[type=search] {
        flex: 0 1 20rem;
        margin: 0;
    }

    .item-layout {
        display: grid;
        grid-template-columns: 2fr 3fr;
        gap: 1.5rem;
        align-items: start;
    }

    .item-media {
        position: sticky;
        top: 1rem;
        max-height: calc(100vh - 2rem);
        padding: 0.25rem;
        overflow-y: auto;
    }

    .photo-main {
        display: block;
        width: 100%;
        aspect-ratio: 4 / 3;
        margin-bottom: 1rem;
        object-fit: contain;
        border-radius: var(--pico-border-radius);
        background: var(--z-card);
    }

    .photo-pick[aria-pressed="true"] {
        outline: 3px solid var(--pico-primary);
        outline-offset: -3px;
    }

    /* :not(.narrow): the login card keeps its 24rem */
    .page-card:not(.narrow) {
        max-width: 720px;
    }

    .tiles {
        grid-template-columns: repeat(4, 1fr);
    }
}
