/* The public page of a published recipe (docs/recipes.md, "Sharing"). It is the
 * app's published recipe view in server-rendered markup: web/bsub/src/pages/
 * recipes/browse/$handle/$slug/$versionNo.tsx for the header and
 * web/bsub/src/Components/Recipe/RecipeSheet.module.css for the sheet, whose
 * rules this restates with the site's tokens (site.css). The app's Radix grays map
 * to --muted (text), --border (rules) and --soft (fills). Keep the two in step. */

.rs-page {
    --rs-rule: var(--border);
    --rs-rule-soft: color-mix(in srgb, var(--border) 55%, transparent);

    max-width: 72rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

/* Header: the cover at the top left with the title beside it. */

.rs-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-3);
}

.rs-media {
    flex: none;
    width: 6.5rem;
    max-width: 100%;
}

.rs-photo {
    display: block;
    width: auto;
    height: auto;
    max-width: min(100%, 20rem);
    max-height: 20rem;
    border-radius: var(--radius-4);
    background: var(--soft);
}

.rs-title {
    flex: 1 1 0;
    min-width: 8rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.rs-title h1 {
    margin: 0;
    font-size: var(--font-size-7);
    line-height: var(--line-height-7);
    overflow-wrap: anywhere;
}

.rs-eyebrow {
    margin: 0;
    color: var(--muted);
    font-family: var(--font-serif);
    font-size: var(--font-size-3);
    line-height: var(--line-height-3);
    font-style: italic;
}

.rs-eyebrow a {
    color: inherit;
    text-decoration-color: var(--border);
}

.rs-eyebrow a:hover {
    color: var(--fg);
    text-decoration-color: currentColor;
}

.rs-details {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    color: var(--muted);
    font-size: var(--font-size-1);
    line-height: var(--line-height-1);
}

.rs-details .rs-detail-main {
    font-size: var(--font-size-2);
    line-height: var(--line-height-2);
}

/* Actions: the call to action at the left, the units at the right. */

.rs-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.rs-login {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0 var(--space-3);
    color: var(--fg);
    font-weight: 500;
    text-decoration: none;
}

.rs-login:hover {
    color: var(--fg);
    text-decoration: underline;
}

.rs-units {
    display: inline-flex;
    margin-left: auto;
    padding: 2px;
    border-radius: var(--radius-3);
    background: var(--soft);
}

.rs-units a {
    display: inline-flex;
    align-items: center;
    height: 1.75rem;
    padding: 0 var(--space-3);
    border-radius: calc(var(--radius-3) - 2px);
    color: var(--muted);
    font-size: var(--font-size-2);
    font-weight: 500;
    text-decoration: none;
}

.rs-units a:hover {
    color: var(--fg);
}

.rs-units a[aria-current="true"] {
    background: var(--panel);
    color: var(--fg);
    box-shadow: var(--shadow-raised);
}

/* The sheet: notes, an estimates band and the stages, ruled sections on the
 * page. Its width, not the window's, decides the layout. */

.rs-sheet {
    container: sheet / inline-size;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    font-variant-numeric: tabular-nums;
}

.rs-notes {
    margin: 0;
    max-width: 72ch;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: var(--font-size-2);
    line-height: 1.5;
}

.rs-muted {
    font-size: var(--font-size-1);
    line-height: 16px;
    color: var(--muted);
}

.rs-band {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
    gap: var(--space-3) var(--space-4);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--rs-rule);
}

.rs-figure {
    min-width: 0;
}

.rs-figure-value {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-5);
    line-height: 28px;
    font-weight: 500;
    white-space: nowrap;
}

.rs-swatch {
    flex: none;
    width: 14px;
    height: 14px;
    border-radius: 2px;
    border: 1px solid var(--rs-rule);
}

.rs-stages {
    display: block;
}

.rs-stage {
    container: stage / inline-size;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-6);
    padding-top: var(--space-3);
    border-top: 1px solid var(--rs-rule);
    break-inside: avoid;
}

.rs-stage-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
}

.rs-stage-head h2 {
    margin: 0;
    font-size: var(--font-size-4);
    line-height: var(--line-height-4);
}

.rs-summary {
    font-size: var(--font-size-1);
    color: var(--muted);
    text-align: right;
}

.rs-facts {
    --fact-min: 9rem;

    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--fact-min), 1fr));
    gap: var(--space-2) var(--space-4);
    margin: 0;
}

.rs-facts-short {
    --fact-min: 4rem;
}

.rs-fact {
    min-width: 0;
}

.rs-fact dt {
    font-size: var(--font-size-1);
    line-height: 16px;
    color: var(--muted);
}

.rs-fact dd {
    margin: 0;
    font-weight: 500;
}

.rs-stage-line,
.rs-stage-notes {
    margin: 0;
    font-size: var(--font-size-2);
    line-height: 1.5;
}

.rs-stage-notes {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* One grid per table, its rows on its columns (subgrid): the values are only as
 * wide as their widest, aligned down the table, and the name takes the rest. */

.rs-table {
    --cols: minmax(0, 1fr) max-content;

    display: grid;
    grid-template-columns: var(--cols);
    column-gap: var(--space-3);
}

.rs-cols-2 {
    --cols: minmax(0, 1fr) repeat(2, max-content);
}

.rs-cols-3 {
    --cols: minmax(0, 1fr) repeat(3, max-content);
}

.rs-cols-4 {
    --cols: minmax(0, 1fr) repeat(4, max-content);
}

.rs-table thead,
.rs-table tbody {
    display: contents;
}

.rs-table :is(th, td) {
    padding: 0;
    font-weight: inherit;
    text-align: left;
}

.rs-row {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: baseline;
}

.rs-head-row {
    padding-bottom: var(--space-1);
    font-size: var(--font-size-1);
    line-height: 16px;
    color: var(--muted);
}

.rs-table tbody .rs-row {
    padding-block: 6px;
    border-top: 1px solid var(--rs-rule-soft);
}

.rs-table-title {
    margin: 0;
    min-width: 0;
    font-family: var(--font-sans);
    font-size: var(--font-size-2);
    line-height: 20px;
    font-weight: 600;
    color: var(--fg);
}

.rs-cell {
    min-width: 0;
    white-space: nowrap;
}

.rs-table th.rs-cell:first-child {
    white-space: normal;
}

.rs-table .rs-end {
    text-align: right;
}

.rs-name-cell {
    min-width: 0;
}

.rs-name-line {
    display: flex;
    align-items: center;
}

.rs-name {
    min-width: 0;
    overflow-wrap: break-word;
}

/* A warning badge right after the name, as the app's amber Badge: a cryo hop's "CRYO". */
.rs-tag {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 0 0.375em;
    border-radius: var(--radius-1);
    background: var(--warning-soft);
    color: var(--warning-text);
    font-size: var(--font-size-1);
    font-weight: 500;
    line-height: var(--line-height-1);
    vertical-align: middle;
}

/* The muted text wraps as a unit: beside the name if it fits, else whole on the next line. */
.rs-detail {
    display: inline-block;
    margin-left: var(--space-2);
    font-size: var(--font-size-1);
    color: var(--muted);
}

.rs-note {
    font-size: var(--font-size-1);
    line-height: 18px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.rs-meta {
    display: none;
    grid-column: 1 / -1;
    font-size: var(--font-size-1);
    line-height: 18px;
    color: var(--muted);
}

/* Ingredient kind icons, in the app's colors for both light and dark surfaces. */
.rs-kind {
    flex: none;
    margin-right: var(--space-2);
}

.rs-kind-fermentables {
    color: #b58a2b;
}

.rs-kind-hops,
.rs-kind-hopExtracts {
    color: #4c9654;
}

.rs-kind-cultures {
    color: #a17ac4;
}

.rs-kind-fruits {
    color: #ce6571;
}

.rs-kind-additives {
    color: #4f8fc7;
}

/* A hop's flag: its slot keeps names aligned when the country is unknown. */
.rs-flag {
    flex: none;
    display: inline-block;
    width: 1.333em;
    margin-right: var(--space-2);
    line-height: 1;
}

.rs-flag img {
    display: block;
    width: 1.333em;
    height: 1em;
    border-radius: 2px;
}

.rs-malt {
    flex: none;
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: var(--space-2);
    border-radius: var(--radius-1);
    box-shadow: 0 0 0 1px var(--rs-rule);
}

/* Two balanced columns, reading down the left and then the right. */
@container sheet (min-width: 60rem) {
    .rs-stages {
        column-count: 2;
        column-gap: var(--space-8);
    }
}

@container sheet (max-width: 36rem) {
    .rs-band {
        grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
    }

    .rs-figure-value {
        font-size: var(--font-size-4);
    }
}

/* A table with more than two value columns keeps the name and the amount on the
 * first line and joins the other values into one muted line under it. */
@container stage (max-width: 32rem) {
    .rs-collapsible {
        grid-template-columns: minmax(0, 1fr) max-content;
    }

    .rs-collapsible .rs-extra {
        display: none;
    }

    .rs-collapsible .rs-meta {
        display: block;
    }
}

@media (min-width: 40em) {
    .rs-media {
        width: 8rem;
    }

    .rs-header {
        gap: var(--space-5);
    }

    .rs-title {
        min-width: 10rem;
    }

    .rs-title h1 {
        font-size: var(--font-size-8);
        line-height: var(--line-height-8);
    }
}

@media (min-width: 48em) {
    .rs-media {
        width: auto;
    }
}

@media (max-width: 30em) {
    .rs-actions .hero-link,
    .rs-login,
    .rs-units a {
        min-height: 2.75rem;
    }

    .rs-units a {
        height: auto;
    }
}

@media print {
    .rs-actions {
        display: none;
    }
}

.rs-cta {
    gap: var(--space-2);
}

/* A newer published version: a quiet line above the actions. */

.rs-newer {
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-3);
    background: var(--soft);
    color: var(--muted);
    font-size: var(--font-size-2);
    line-height: var(--line-height-2);
}

.rs-newer a {
    color: var(--accent-text);
    font-weight: 500;
}

/* The history menu: a popover under its button, no script involved. */

.rs-history-button {
    gap: var(--space-2);
    padding: 0 var(--space-4);
    margin-left: auto;
    font-family: inherit;
    cursor: pointer;
    anchor-name: --rs-history;
}

.rs-history-button ~ .rs-units {
    margin-left: 0;
}

.rs-history {
    width: min(22rem, calc(100vw - 2 * var(--space-4)));
    max-height: min(24rem, 70vh);
    margin: 0;
    padding: var(--space-1);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-4);
    background: var(--panel);
    color: var(--fg);
    box-shadow: var(--shadow-card);
    transform-origin: top right;
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
    transition:
        opacity 150ms ease,
        transform 150ms ease,
        overlay 150ms ease allow-discrete,
        display 150ms ease allow-discrete;
}

.rs-history:popover-open {
    opacity: 1;
    transform: none;
}

@starting-style {
    .rs-history:popover-open {
        opacity: 0;
        transform: translateY(-4px) scale(0.97);
    }
}

/* Without anchor positioning the menu stays where a popover sits by default,
 * centered in the window. */
@supports (anchor-name: --a) {
    .rs-history {
        position-anchor: --rs-history;
        inset: auto;
        top: anchor(bottom);
        right: anchor(right);
        margin-top: var(--space-1);
        position-try-fallbacks: flip-block;
    }
}

.rs-history ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.rs-history-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-3);
    color: var(--fg);
    text-decoration: none;
}

a.rs-history-item:hover,
a.rs-history-item:focus-visible {
    background: var(--soft);
    color: var(--fg);
}

.rs-history-item[aria-current="true"] {
    background: var(--accent-soft);
}

.rs-history-no {
    font-size: var(--font-size-2);
    font-weight: 500;
}

.rs-history-meta {
    color: var(--muted);
    font-size: var(--font-size-1);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* Moving between versions, and switching units, is a transition rather than a
 * flash: the cover and title stay put and the sheet fades up. Each name is on
 * one element per page. */

@view-transition {
    navigation: auto;
}

.rs-photo {
    view-transition-name: rs-cover;
}

.rs-title h1 {
    view-transition-name: rs-title;
}

.rs-sheet {
    view-transition-name: rs-sheet;
}

::view-transition-group(root) {
    animation-duration: 200ms;
}

::view-transition-group(rs-sheet) {
    overflow: clip;
}

::view-transition-old(rs-sheet),
::view-transition-new(rs-sheet) {
    height: 100%;
    object-fit: cover;
    object-position: top;
}

::view-transition-old(rs-sheet) {
    animation: rs-sheet-out 160ms ease both;
}

::view-transition-new(rs-sheet) {
    animation: rs-sheet-in 260ms ease 60ms both;
}

@keyframes rs-sheet-out {
    to {
        opacity: 0;
    }
}

@keyframes rs-sheet-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }

    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }

    .rs-history {
        transition: none;
    }
}

@media print {
    .rs-newer {
        display: none;
    }
}
