/* Recipes page, recipe editor and shopping list. */

/* ---------- Recipe cards ---------- */

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.recipe-card {
    min-height: 150px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}

.recipe-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.recipe-card__name { font-size: 1.05rem; }
.recipe-card__meta { color: var(--accent); font-size: 0.78rem; font-weight: 600; }

.recipe-card__ingredients {
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: var(--ink-muted);
    font-size: 0.86rem;
}

.recipe-card__ingredients span { color: var(--ink); font-variant-numeric: tabular-nums; }
.recipe-card__more { font-style: italic; }

/* ---------- Editor ---------- */

.recipe-editor__form { display: flex; flex-direction: column; gap: 16px; }
.recipe-editor__head { display: flex; flex-wrap: wrap; gap: 12px; }

.recipe-field { display: flex; flex-direction: column; gap: 5px; }
.recipe-field > span { color: var(--ink-muted); font-size: 0.8rem; font-weight: 600; }
.recipe-field--grow { flex: 1; min-width: 220px; }
.recipe-field--small { width: 110px; }

.recipe-field input,
.recipe-field textarea,
.ingredient-row input {
    width: 100%;
    min-width: 0;
}

.recipe-field textarea { resize: vertical; line-height: 1.5; }

.recipe-field input:focus,
.recipe-field textarea:focus,
.ingredient-row input:focus { outline: none; border-color: var(--accent); }

.recipe-editor__ingredients { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 6px; }
.recipe-editor__ingredients legend { margin-bottom: 8px; padding: 0; font-weight: 600; }
.recipe-editor__ingredients legend small { margin-left: 6px; color: var(--ink-muted); font-weight: 400; }

.ingredient-row {
    display: grid;
    grid-template-columns: 90px 90px 1fr 36px;
    align-items: center;
    gap: 6px;
}

.ingredient-row--labels { color: var(--ink-muted); font-size: var(--text-xs); font-weight: 600; }
.ingredient-row--labels span { padding-left: 4px; }
.ingredient-row.is-invalid input:first-child { border-color: var(--danger); }

.recipe-editor__hint { margin: 4px 0 0; color: var(--ink-muted); font-size: 0.8rem; }

.recipe-editor__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.recipe-editor__actions .secondary-button { margin: 0; }
.recipe-editor__spacer { flex: 1; }

/* ---------- Shopping list ---------- */

.shopping {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    align-items: start;
    gap: 16px;
}

.shopping .card { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.shopping h2 { margin: 0; font-size: 1.05rem; }
.shopping h3 { margin: 0; font-size: var(--text-md); color: var(--ink-muted); }
.shopping .primary-button { text-decoration: none; align-self: flex-start; }

.shopping__recipes {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 55vh;
    overflow-y: auto;
}

.shopping__recipes li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.shopping__recipes li.is-selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.shopping__recipes label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.shopping__recipes label > span { min-width: 0; display: flex; flex-direction: column; }
.shopping__recipes strong { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shopping__recipes small { color: var(--ink-muted); font-size: var(--text-xs); }

.stepper { display: inline-flex; align-items: center; gap: 2px; font-variant-numeric: tabular-nums; }
.stepper > span { min-width: 22px; text-align: center; font-weight: 600; }
.stepper .icon-button { width: 28px; height: 28px; font-size: 1rem; line-height: 1; }
.stepper .icon-button:disabled { opacity: 0.4; cursor: default; }

.shopping__generate { display: flex; flex-wrap: wrap; gap: 8px; }
.shopping__generate .secondary-button { margin: 0; }

.shopping__list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shopping__done-head { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); }

.shopping__add .shopping__add-amount { flex: 0 0 70px; }
.shopping__add .shopping__add-unit { flex: 0 0 96px; }
.shopping__add input { color: var(--ink); }
.shopping__add .primary-button { align-self: auto; }

.shopping__items { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }

.shopping-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
    border-bottom: 1px solid var(--line);
}

.shopping-item:last-child { border-bottom: 0; }
.shopping-item label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.shopping-item input[type="checkbox"], .shopping__recipes input[type="checkbox"] { flex: none; }

.shopping-item__text { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
.shopping-item__text strong { font-variant-numeric: tabular-nums; }
.shopping-item__text small { flex-basis: 100%; color: var(--ink-muted); font-size: var(--text-xs); }

.shopping-item .icon-button { opacity: 0; transition: opacity 0.15s; }
.shopping-item:hover .icon-button, .shopping-item .icon-button:focus-visible { opacity: 1; }

.shopping-item.is-checked .shopping-item__text { color: var(--ink-muted); text-decoration: line-through; }

@media (hover: none) {
    .shopping-item .icon-button { opacity: 1; }
}

@media (max-width: 760px) {
    .shopping { grid-template-columns: minmax(0, 1fr); }
    /* In the shop the list itself matters most. */
    .shopping__list { order: -1; }
    .shopping__add { flex-wrap: wrap; }
    .shopping__add input:not(.shopping__add-amount) { flex-basis: 100%; order: -1; }
    .shopping__add .shopping__add-amount, .shopping__add .shopping__add-unit { flex: 1 1 60px; }
    .ingredient-row { grid-template-columns: 64px 64px 1fr 32px; }
}

/* ---------- Week planner ---------- */

.shopping__side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.shopping__planner .primary-button svg { width: 16px; height: 16px; }

.planner__fields { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 8px; }
.planner__fields .recipe-field > span { font-size: 0.72rem; }

.planner__weeks {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 40vh;
    overflow-y: auto;
}

.planner__weeks > li > strong { font-size: var(--text-sm); }

.planner__meals {
    margin: 4px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.86rem;
}

.planner__meals span { display: inline-block; min-width: 30px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ---------- Language choice (settings) ---------- */

.language-tabs { width: fit-content; margin-bottom: 6px; }

/* ---------- Supermarket aisles ---------- */

.shopping__aisle {
    margin: 10px 0 0;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.shopping__aisle:first-of-type { margin-top: 0; }

.offline-banner {
    margin: 0;
    padding: 10px 14px;
    border: 1px solid var(--accent);
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    font-size: 0.9rem;
}

/* ---------- Meal plan ---------- */

.plan { display: grid; grid-template-columns: 1fr minmax(260px, 340px); align-items: start; gap: 16px; }
.plan__weeks, .plan__side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.plan__week, .plan__tool { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.plan__week h2, .plan__tool h2 { margin: 0; font-size: 1rem; }
.plan__days { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }

.plan-day {
    display: grid;
    grid-template-columns: 64px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.plan-day:last-child { border-bottom: 0; }
.plan-day[draggable="true"] { cursor: grab; }
.plan-day.is-today { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.plan-day.is-today .plan-day__date strong { color: var(--accent); }
.plan-day.is-past { opacity: 0.55; }
.plan-day.is-drop-target { outline: 1.5px dashed var(--accent); }

.plan-day__date { display: flex; flex-direction: column; line-height: 1.2; }
.plan-day__date small { color: var(--ink-muted); font-size: var(--text-xs); }

.plan-day__dish, .plan-day__servings {
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.plan-day__servings { width: 62px; }
.plan-day__tools { display: inline-flex; gap: 2px; }
.plan-day__tools svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.plan__tool .primary-button svg { width: 16px; height: 16px; }

/* ---------- Household (settings) ---------- */

.household__members { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.household__members li { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.household__members small { color: var(--ink-muted); }
.household__avatar { width: 30px; height: 30px; font-size: var(--text-sm); }

.household__code {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 2px 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px dashed var(--accent);
    border-radius: 12px;
}

.household__code > span { grid-column: 1 / -1; color: var(--ink-muted); font-size: 0.78rem; }
.household__code strong { font-family: ui-monospace, monospace; font-size: var(--text-xl); letter-spacing: 0.15em; }
.household__code small { grid-column: 1 / -1; color: var(--ink-muted); font-size: 0.78rem; }
.household__join { margin: 10px 0 4px; }

@media (max-width: 860px) {
    .plan { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 520px) {
    .plan-day { grid-template-columns: 52px 1fr auto; }
    .plan-day__tools { grid-column: 2 / -1; justify-self: end; }
}

/* ---------- Floating shopping button ---------- */

/* Phones only: on a computer nobody shops with it, and the shopping list is one click away. */
@media (min-width: 721px) {
    .shani .fabs { display: none; }
}

.fabs {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 15;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.shop-fab {
    position: relative;
    border: 0;
    cursor: pointer;
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    box-shadow: 0 10px 30px rgb(0 0 0 / 35%);
    transition: transform 0.15s;
}

.shop-fab:hover { transform: translateY(-2px); }
.shop-fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.shop-fab__count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    border: 2px solid var(--bg);
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: var(--bg);
    font-size: 0.72rem;
    font-weight: 700;
}

/* The desktop music player sits in the same corner: stay above it. */
.shani:has(.mini-player, .mini-player-bubble) .fabs { bottom: 96px; }

/* ---------- Shopping mode ---------- */

.shop { width: 100%; max-width: 640px; margin: 0 auto; padding-bottom: 110px; display: flex; flex-direction: column; gap: 12px; }
.shop__head { display: flex; flex-direction: column; gap: 10px; }
.shop__title { display: flex; align-items: center; justify-content: space-between; }
.shop__title h1 { font-size: 2rem; }
.shop__progress { margin: 0; color: var(--ink-muted); }

.shop__items { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }

.shop-item {
    width: 100%;
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.shop-item:active { transform: scale(0.99); }

.shop-item__box {
    width: 26px;
    height: 26px;
    flex: none;
    display: grid;
    place-items: center;
    border: 2px solid var(--ink-muted);
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.shop-item__box.is-checked { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.shop-item__text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.shop-item__name { font-size: 1.05rem; }
.shop-item__name strong { margin-right: 6px; font-variant-numeric: tabular-nums; }
.shop-item__text small { color: var(--ink-muted); font-size: 0.8rem; }

.shop__items.is-done .shop-item { opacity: 0.75; }
.shop__items.is-done .shop-item__name { text-decoration: line-through; }
.shop__all-done { margin: 0; font-weight: 600; }
.shop__basket-title { margin-top: 14px; }

.shop__finish {
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 15;
    width: min(608px, calc(100% - 32px));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg);
    box-shadow: 0 10px 40px rgb(0 0 0 / 40%);
}

.shop__finish p { margin: 0; }
.shop__finish-button { justify-content: center; width: 100%; padding: 14px; font-size: 1rem; }

/* On phones the floating buttons sit over the footer's right side: keep the text left of them. */
@media (max-width: 720px) {
    .shani:has(.fabs) .app-footer { padding-right: 84px; justify-content: flex-start; text-align: left; }
}

/* ---------- Bottom sheets (dialogs) ---------- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 45%); animation: shani-fade 0.2s ease; }

.sheet {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 31;
    width: min(560px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 18px max(18px, env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    background: var(--bg);
    color: var(--ink);
    box-shadow: 0 -12px 40px rgb(0 0 0 / 35%);
    animation: shani-rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet__head { display: flex; align-items: center; justify-content: space-between; }
.sheet__head h2 { margin: 0; font-size: var(--text-lg); }
.sheet input { color: var(--ink); }

.recipe-card-wrap { display: flex; flex-direction: column; gap: 6px; }
.recipe-card-wrap .recipe-card { flex: 1; }

/* ---------- Footer ---------- */

.app-footer {
    margin: 0 clamp(16px, 4vw, 40px);
    padding: 18px 0 8px;
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 16px;
    color: var(--ink-muted);
    font-size: var(--text-xs);
    text-align: center;
}

.app-footer a { color: inherit; }

/* Connection lights: green answers, red doesn't. */
.health { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 2px 10px; }
.health__item { display: inline-flex; align-items: center; gap: 5px; cursor: default; }
.health__dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.health__dot.is-up { background: #3fb950; box-shadow: 0 0 6px color-mix(in srgb, #3fb950 70%, transparent); }
.health__dot.is-down { background: #f85149; box-shadow: 0 0 6px color-mix(in srgb, #f85149 70%, transparent); animation: health-blink 1.6s ease-in-out infinite; }
@keyframes health-blink { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .health__dot.is-down { animation: none; } }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Week planner: every row keeps the same columns (dish, servings, tools), also when the day is empty. */
@media (min-width: 521px) {
    .plan-day { grid-template-columns: 64px minmax(0, 1fr) 62px 104px; }
    .plan-day__tools { justify-content: flex-end; }
}

/* ---------- Planning dialog (offer flyer → recipes for the plan) ---------- */

.plan-wizard p { margin: 0; }
.plan-wizard__choices { display: flex; flex-wrap: wrap; gap: 8px; }

/* The file input sits invisibly over its button-styled label: tapping the label picks the file. */
.plan-wizard__pick { position: relative; cursor: pointer; }
.plan-wizard__pick svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.plan-wizard__pick input[type=file] { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.plan-wizard__pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.plan-wizard__recipes { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.plan-wizard__recipes li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; }
.plan-wizard__recipes li.is-selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.plan-wizard__recipes label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.plan-wizard__recipes label > span { display: flex; flex-direction: column; min-width: 0; }
.plan-wizard__recipes small { color: var(--ink-muted); font-size: 0.8rem; }

/* On larger screens it's a small dialog in the middle rather than a sheet from the bottom. */
@media (min-width: 721px) {
    .sheet.plan-wizard { top: 50%; bottom: auto; transform: translate(-50%, -50%); border-bottom: 1px solid var(--line); border-radius: var(--radius-xl); animation: shani-fade 0.2s ease; }
}

/* ---------- Narrow screens (folded phones' cover screens, ~280–360px) ---------- */

@media (max-width: 420px) {
    /* The dish gets the whole width; servings and tools go below it. */
    .plan-day { grid-template-columns: 46px minmax(0, 1fr) auto; row-gap: 6px; }
    .plan-day__dish { grid-column: 2 / -1; }
    .plan-day__servings { grid-column: 2; justify-self: start; }
    .plan-day__tools { grid-column: 3; }
    .shopping .card, .plan__tool { padding: 14px; }
}

/* ---------- Foldables spread over both screens (two viewport segments) ----------
   The page is centred, so two equal columns with the hinge as their gap keep everything off the fold. */

@media (horizontal-viewport-segments: 2) {
    .plan, .shopping {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        column-gap: calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px) + 32px);
    }
    /* Shopping mode stays on the left screen. */
    .shop { margin-left: 0; max-width: calc(env(viewport-segment-width 0 0, 100%) - 32px); }
    .sheet { left: 0; transform: none; width: env(viewport-segment-width 0 0, 100%); }
}

/* Folded like a laptop (top and bottom screen): dialogs stay on the bottom half. */
@media (vertical-viewport-segments: 2) {
    .sheet { max-height: calc(100dvh - env(viewport-segment-top 0 1, 50dvh)); }
}

/* ---------- Start page: today's dish ---------- */

.todays-dish {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    width: fit-content;
    max-width: 100%;
    margin-top: 14px;
    padding: 10px 16px 10px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    transition: border-color 0.15s;
}
.todays-dish:hover { border-color: var(--accent); }
.todays-dish__icon { width: 42px; height: 42px; display: grid; place-items: center; flex: none; border-radius: 12px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.todays-dish__icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.todays-dish__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.todays-dish__text small { color: var(--accent); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.todays-dish__text strong { font-size: 1.05rem; }
.todays-dish__text span { color: var(--ink-muted); font-size: 0.8rem; }
.todays-dish__next { padding-left: 14px; border-left: 1px solid var(--line); color: var(--ink-muted); font-size: 0.82rem; }
