/*
 * Plans: the open list's name and its List | Plan switch, what was added
 * to it (entry rows, as on Meals and Groups), and the pickers for adding
 * items, groups and saved meals.
 */
@layer components {
  .plan-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    margin-bottom: var(--space-4);
  }
  .plan-bar__name { min-width: 0; }
  .plan-bar__name summary { display: flex; align-items: center; gap: var(--space-2); list-style: none; cursor: pointer; }
  .plan-bar__name summary::-webkit-details-marker { display: none; }
  .plan-bar__name h2 { font-size: var(--text-xl); }
  .plan-bar__rename { display: inline-grid; color: var(--muted); }
  .plan-bar__rename svg { width: 16px; height: 16px; }
  .plan-bar__name[open] .inline-form { margin-top: var(--space-3); }
  /* What's been added, weighted like List's progress label: the total strong, the breakdown muted. */
  .plan-summary { margin: 0; font-weight: 700; color: var(--muted); }
  .plan-summary strong { color: var(--ink); font-weight: 800; }

  .add-bigger { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-3); }
  .add-bigger svg { width: 18px; height: 18px; }

  .plan-view { display: grid; gap: var(--space-4); }
  .plan-view .entry-list { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
  .plan-direct__items { display: grid; gap: var(--space-1); margin: 0; padding: var(--space-3) var(--space-4); list-style: none;
    border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); font-weight: 700; }
  .plan-direct__items li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); }
  .plan-direct__save { margin-left: auto; color: var(--muted); font-size: var(--text-sm); font-weight: 700; }
  .plan-direct__hint { margin: 0 0 var(--space-2); }
  .plan-fixed { display: grid; gap: var(--space-1); list-style: none; font-weight: 700; }
  .list-actions--end { justify-content: flex-end; margin-top: var(--space-5); }

  /* Picking items, groups or meals: a tick, the name, and this list's amount. */
  .picker { display: grid; gap: var(--space-4); }
  .picker .picker__section { margin-bottom: 0; }
  .picker .group-section__heading { margin-right: 0; }
  .picker__list { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
  .picker__row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); }
  .picker__row + .picker__row { border-top: 1px solid var(--line); }
  .picker__row[hidden] { display: none; }
  .picker__row:has(.picker__error) { flex-wrap: wrap; }
  .picker__error { flex-basis: 100%; margin: 0; }
  .picker__choice { display: flex; flex: 1; align-items: center; gap: var(--space-3); min-width: 0; min-height: var(--touch); cursor: pointer; }
  .picker__choice .check-field__box { margin-top: 0; }
  .picker__amount-label { color: var(--muted); font-size: var(--text-xs); font-weight: 800; }
  .picker__amount { width: 7rem; }
  .picker__servings { display: flex; flex: none; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--text-sm); font-weight: 800; }
  .picker__servings-input { width: 4.25rem; text-align: center; }
  .picker__actions { position: sticky; bottom: calc(max(var(--space-3), env(safe-area-inset-bottom)) + 76px); }
  @media (min-width: 768px) { .picker__actions { position: static; } }
  @media (max-width: 479px) { .picker__amount-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } }

  /* Browse: the same picker in a sheet over the list. A centred panel on wider
     screens; the whole screen on phones, so the list of items gets the room.
     Only the list scrolls; the heading and the Add button stay put. */
  .picker-dialog {
    width: min(560px, calc(100vw - 2 * var(--space-4)));
    max-height: min(85dvh, 760px);
    inset: 0;
    margin: auto;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--cream);
    color: var(--ink);
    box-shadow: var(--shadow-float);
  }
  .picker-dialog[open] { display: flex; flex-direction: column; }
  .picker-dialog::backdrop { background: rgb(43 42 39 / 0.45); }
  .picker-dialog turbo-frame { display: flex; flex-direction: column; min-height: 0; flex: 1; }
  .picker-dialog turbo-frame:empty { min-height: 240px; }
  .picker-dialog .picker-dialog__header { margin: 0; padding: var(--space-4) var(--space-4) var(--space-3); }
  .picker-dialog .picker-dialog__header h1 { font-size: var(--text-xl); }
  .picker-dialog .picker-dialog__header p { margin: 0; }
  .picker-dialog turbo-frame > .field__error { margin: 0 var(--space-4) var(--space-2); }
  .picker-dialog .picker { flex: 1; min-height: 0; grid-template-rows: auto 1fr auto; gap: var(--space-3); padding: 0 var(--space-4); }
  .picker-dialog .picker__list { overflow-y: auto; min-height: 0; }
  .picker-dialog .picker__actions { position: static; margin: 0 calc(-1 * var(--space-4)); padding: var(--space-3) var(--space-4) max(var(--space-3), env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); background: var(--cream); }
  .picker-dialog .empty-state { margin: 0 var(--space-4) var(--space-4); }
  @media (max-width: 639px) {
    .picker-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0; }
  }
}
