/*
 * Copyright (c) 2026 by Gabriele Proietti Mattia <pm.gabriele@gmail.com>.
 *
 * All Rights Reserved.
 */

/*
 * The Plan tab (plan.js): the plan of the week and the screens that open from it. The pieces shared
 * with the other tabs (pills, notes, steppers, sub-pages, sheets, the dock) are in kit.css; here is
 * only what is the plan's own, with the tokens of the design system and the few of kit.css.
 */

/* ----------------------------------------------------------------------------------- header */

#plan-root { display: flex; flex-direction: column; gap: var(--space-4); }

.plan-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.plan-head__titles { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.plan-head__actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); }

/* the small round button of the header: "+ Ricetta", "Piani passati" */
.plan-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: var(--border-hairline) solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-pill svg { width: 18px; height: 18px; }

/* every button of the plan shows where the keyboard is */
.plan-pill:focus-visible, .plan-missing:focus-visible, .plan-day__date:focus-visible,
.plan-strip__day:focus-visible, .plan-row:focus-visible, .plan-cell:focus-visible, .plan-group__row:focus-visible,
.plan-link:focus-visible, .plan-fold:focus-visible, .plan-past__head:focus-visible,
.plan-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.plan-btn { flex: 1 1 auto; }
.plan-btn.button--ghost { background: var(--surface-2); }

/* ------------------------------------------------------------------------------- main card */

.plan-main { gap: var(--space-3); border-color: var(--accent-soft-border); }
.plan-main__count { font-weight: var(--fw-medium); color: var(--text-muted); }
.plan-main__time { font-size: var(--fs-h1); font-weight: var(--fw-semibold); line-height: var(--lh-tight); font-variant-numeric: tabular-nums; }
.plan-main__sub { margin-top: calc(var(--space-2) * -1); font-size: var(--fs-body-sm); color: var(--text-muted); }
.plan-main__buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.plan-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.plan-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: var(--border-hairline) solid var(--border);
  color: var(--text);
  font-size: var(--fs-caption);
}

.plan-chip__n { color: var(--text-muted); }

/* ----------------------------------------------------------------------- what is missing */

.plan-missing {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-missing__tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--warn-soft);
  color: var(--warn);
}

.plan-missing__tile--ok { background: var(--success-soft); color: var(--success); }
.plan-missing__tile svg { width: 20px; height: 20px; }
.plan-missing__text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.plan-missing__title { font-weight: var(--fw-medium); }
.plan-missing__sub { font-size: var(--fs-caption); color: var(--text-muted); }
.plan-missing__go { flex: none; width: 20px; height: 20px; color: var(--text-subtle); }

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

.plan-buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) 0;
  border-bottom: var(--border-hairline) solid var(--border-faint);
}

.plan-buy__text { display: flex; flex-direction: column; min-width: 0; }
.plan-buy__name { font-weight: var(--fw-medium); }
.plan-buy__note { font-size: var(--fs-caption); color: var(--text-muted); }
.plan-buy__amount { flex: none; font-variant-numeric: tabular-nums; color: var(--text-muted); }

.plan-actions { display: flex; flex-direction: column; gap: var(--space-2); }
.plan-send { flex-direction: column; gap: 0; }
.plan-send__main { font-weight: var(--fw-medium); }
.plan-send__sub { font-size: var(--fs-caption); opacity: 0.85; }
.plan-sent { margin: 0; padding: var(--space-3); border-radius: var(--radius-md); background: var(--success-soft); color: var(--success); font-weight: var(--fw-medium); }

.plan-dock { display: flex; flex-direction: column; gap: var(--space-4); }
.plan-dock__title { margin: 0; font-size: var(--fs-h3); line-height: var(--lh-heading); }

/* ----------------------------------------------------------------------------- the week */

.plan-week { gap: var(--space-2); }
.plan-week .group__title { margin-bottom: var(--space-1); }

.plan-day {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2);
  background: var(--surface);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-lg);
}

.plan-day__date {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-date { display: flex; flex-direction: column; align-items: center; line-height: var(--lh-snug); }
.plan-date__wd { font-family: var(--font-mono); font-size: var(--fs-mono-label); text-transform: uppercase; color: var(--text-muted); }
.plan-date__n { font-size: var(--fs-h3); font-weight: var(--fw-semibold); }

.plan-day__rows { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.plan-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-row--idle { cursor: default; }
.plan-row__slot { flex: none; width: 76px; font-size: var(--fs-caption); color: var(--text-muted); }
.plan-row__name { flex: 1 1 auto; min-width: 0; font-weight: var(--fw-medium); overflow-wrap: anywhere; }
.plan-row__name--open { font-weight: var(--fw-regular); color: var(--accent); }
.plan-row__name--idle { font-weight: var(--fw-regular); color: var(--text-muted); }
.plan-row__plus { flex: none; width: 18px; height: 18px; color: var(--accent); }

.plan-frozen { flex: none; display: inline-flex; color: var(--cold); }
.plan-frozen svg { width: 16px; height: 16px; }

/* the days at a glance, above the day cards of the phone: a long plan scrolls sideways */
.plan-strip {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--surface);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-lg);
}

.plan-strip__line { display: flex; gap: var(--space-1); }
.plan-strip__labels { flex: none; display: flex; flex-direction: column; }
.plan-strip__corner { height: 52px; }
.plan-strip__slot { display: flex; align-items: center; height: 28px; font-size: var(--fs-caption); color: var(--text-muted); }
.plan-strip__days { flex: 1 1 auto; min-width: 0; display: flex; overflow-x: auto; }

.plan-strip__day {
  flex: 1 0 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-strip__day.is-today { background: var(--accent-soft); }
.plan-strip__day.is-today .plan-date__n { color: var(--accent); }
.plan-strip__day .plan-date { justify-content: center; height: 52px; }
.plan-strip__day .plan-date__n { font-size: var(--fs-h4); }
.plan-strip__cell { display: flex; align-items: center; justify-content: center; height: 28px; }

.plan-strip__dot {
  flex: none;
  display: block;
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-circle);
}

.plan-strip__dot--set { border-color: var(--accent); background: var(--accent); }

.plan-strip__legend { display: flex; gap: var(--space-4); padding: 0 var(--space-1); font-size: var(--fs-caption); color: var(--text-muted); }
.plan-strip__key { display: flex; align-items: center; gap: var(--space-2); }

/* the week as a table, for the wide page */
.plan-grid { overflow-x: auto; }
.plan-table { width: 100%; min-width: 560px; border-collapse: separate; border-spacing: var(--space-2); table-layout: fixed; }
.plan-table th, .plan-table td { padding: 0; vertical-align: top; font-weight: var(--fw-regular); }
.plan-table th:first-child, .plan-table td:first-child { width: 72px; }
.plan-table__slot { text-align: left; padding-top: var(--space-3); font-size: var(--fs-caption); color: var(--text-muted); }
.plan-table__day { text-align: center; }
.plan-day__date--grid { width: 100%; }

.plan-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  min-height: 64px;
  padding: var(--space-2);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body-sm);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.plan-cell--open { justify-content: center; white-space: nowrap; border-style: dashed; background: transparent; color: var(--text-muted); }
.plan-cell--open svg { width: 16px; height: 16px; flex: none; }
.plan-cell--idle { cursor: default; color: var(--text-muted); }
.plan-cell.is-selected { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.plan-cell__name { flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; }

/* the snowflake sits on the corner and takes the room of the first line only, so that a long word such
   as "lenticchie" keeps the whole width of the cell under it and is not broken in two */
.plan-cell .plan-frozen { position: absolute; top: var(--space-2); right: var(--space-2); }
.plan-cell:has(.plan-frozen) .plan-cell__name::before { content: ''; float: right; width: 16px; height: 16px; margin-left: var(--space-1); }

/* ---------------------------------------------------------------------------- the figures */

.plan-figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }

.plan-figure {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-lg);
}

.plan-figure__value { font-size: var(--fs-h1); font-weight: var(--fw-semibold); line-height: var(--lh-snug); font-variant-numeric: tabular-nums; }
/* the tile is a container so that the number can shrink with it (a 1.060 does not fit a narrow tile at the size of the others) */
.plan-figure__num { white-space: nowrap; font-size: min(1em, 30cqw); }
.plan-figure__value--small { font-size: var(--fs-body); }
.plan-figure__unit { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); color: var(--text-muted); }
.plan-figure__sub { font-size: var(--fs-caption); color: var(--text-muted); }

/* ------------------------------------------------------------------ "Nuovo piano", "Passati" */

.plan-group { padding: 0; gap: 0; }

.plan-group__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: 0 var(--space-4);
  border: 0;
  border-bottom: var(--border-hairline) solid var(--border-faint);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.plan-group__row svg { flex: none; width: 20px; height: 20px; color: var(--text-muted); }
.plan-group__text { flex: 1 1 auto; }

/* --------------------------------------------------------------------- the first question */

.plan-first { display: flex; flex-direction: column; gap: var(--space-4); }
.plan-first__list { display: flex; flex-direction: column; gap: var(--space-2); }
.plan-tick { flex: none; width: 20px; height: 20px; color: var(--accent); }
.plan-links { display: flex; flex-direction: column; gap: var(--space-2); }

.plan-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-3);
  border: var(--border-hairline) dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.plan-link svg { flex: none; width: 18px; height: 18px; color: var(--text-muted); }
.plan-link__text { flex: 1 1 auto; display: flex; flex-direction: column; }
.plan-link__name { font-weight: var(--fw-medium); }
.plan-link__hint { font-size: var(--fs-caption); color: var(--text-muted); }

/* --------------------------------------------------------------------- the dish of a meal */

.plan-dish .kit-choice__meta { display: flex; flex-wrap: wrap; align-items: center; column-gap: var(--space-1); }
.plan-none { color: var(--warn); }
.plan-cold { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--fs-caption); color: var(--cold); }
.plan-cold svg { width: 14px; height: 14px; }
.plan-need { margin: 0; font-size: var(--fs-body-sm); color: var(--text-muted); }
.plan-foot-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.plan-extra { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-3); }
.plan-extra__text { display: flex; flex-direction: column; min-width: 0; }
.plan-extra__title { font-weight: var(--fw-medium); }
.plan-extra__hint { font-size: var(--fs-caption); color: var(--text-muted); }

/* ------------------------------------------------------------------------------ "Aggiungi" */

.plan-search { margin-bottom: var(--space-2); }
.plan-filter { width: auto; min-height: 44px; margin-bottom: var(--space-2); padding: 0 var(--space-4); border-radius: var(--radius-pill); }
.plan-filter svg { width: 16px; height: 16px; }
.plan-add { display: flex; flex-direction: column; gap: var(--space-2); }

.plan-add__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border: var(--border-hairline) solid var(--border);
  border-radius: var(--radius-lg);
}

.plan-add__text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.plan-expiring { display: flex; align-items: center; gap: var(--space-1); font-size: var(--fs-caption); color: var(--warn); }
.plan-expiring svg { flex: none; width: 14px; height: 14px; }

/* ------------------------------------------------------------------------ "Nuovo piano" */

.plan-new__dates { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.plan-new__date { margin-bottom: 0; }
.plan-new__actions { display: flex; flex-direction: column; gap: var(--space-2); }
.plan-error { margin: 0; color: var(--danger); font-size: var(--fs-body-sm); }
.plan-summary { gap: var(--space-1); }
.plan-summary__title { font-size: var(--fs-h4); font-weight: var(--fw-semibold); }

.plan-warn {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border-hairline) solid var(--warn);
  border-radius: var(--radius-lg);
  background: var(--warn-soft);
  color: var(--text);
}

.plan-warn svg { flex: none; width: 20px; height: 20px; color: var(--warn); }
.plan-warn__text { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-body-sm); }
.plan-warn__title { font-weight: var(--fw-medium); }

/* ---------------------------------------------------------------------------------- "Manca" */

.plan-question { gap: var(--space-2); }
.plan-question__name { font-weight: var(--fw-medium); }

.plan-fold {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.plan-fold svg { width: 18px; height: 18px; color: var(--text-muted); }
.plan-fold[aria-expanded="true"] svg { transform: rotate(180deg); }

/* ---------------------------------------------------------------------------------- "Giorno" */

.plan-meal { gap: var(--space-3); }
.plan-meal__name { font-size: var(--fs-h4); font-weight: var(--fw-semibold); }
.plan-meal__n { font-family: var(--font-mono); font-size: var(--fs-body-sm); color: var(--text-muted); }
.plan-meal__meta { font-size: var(--fs-body-sm); color: var(--text-muted); }
.plan-meal__who { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.plan-meal__label { font-size: var(--fs-caption); color: var(--text-muted); }
.plan-meal__people { display: inline-flex; align-items: center; }
.plan-meal .kit-avatar.is-off .kit-avatar__letter { opacity: 0.35; }
.plan-change { margin-left: auto; min-height: 44px; }
.plan-eaten[aria-pressed="true"] { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.plan-eaten svg { width: 18px; height: 18px; }

.plan-total { gap: var(--space-2); }
.plan-total__row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.plan-total__value { font-size: var(--fs-h2); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.plan-total__unit, .plan-total__goal { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); color: var(--text-muted); }
.plan-total__notes { display: flex; flex-direction: column; gap: var(--space-1); }

.plan-bar { height: 8px; border-radius: var(--radius-pill); background: var(--surface-sunken); overflow: hidden; }
.plan-bar__fill { height: 100%; width: 100%; border-radius: var(--radius-pill); background: var(--accent); transform-origin: left center; }

.plan-gate { gap: var(--space-3); }
.plan-gate__title { font-size: var(--fs-h4); font-weight: var(--fw-semibold); }

/* ------------------------------------------------------------------------- "Piani passati" */

.plan-past { display: flex; flex-direction: column; gap: var(--space-2); }
.plan-past__card { padding: 0; gap: 0; }
.plan-past__card.is-selected { border-color: var(--accent); background: var(--accent-soft); }

.plan-past__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.plan-past__head svg { flex: none; width: 18px; height: 18px; color: var(--text-muted); }
.plan-past__head[aria-expanded="true"] svg { transform: rotate(180deg); }
.plan-past__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.plan-past__title { font-weight: var(--fw-semibold); }
.plan-past__detail { display: flex; flex-direction: column; gap: var(--space-3); padding: 0 var(--space-4) var(--space-4); }

.plan-past__meal {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  min-height: 36px;
  font-size: var(--fs-body-sm);
}

.plan-past__when { color: var(--text-muted); }
.plan-past__dish { overflow-wrap: anywhere; }
.plan-past__state { font-size: var(--fs-caption); color: var(--text-muted); }
.plan-past__state.is-eaten { color: var(--success); }

/* ---------------------------------------------------------------------------------- wide */

@media (min-width: 1180px) {
  .plan-head__titles .screen__title { font-size: var(--fs-h2); }
  .plan-day__date--grid { min-height: 56px; }
}
