/* The structured plan editors (views/plan-editor.js, views/coach-plan-editor.js).
 *
 * One stylesheet for the member app and the professional console, both of
 * which load it after their own. Everything here is prefixed `pe-` so it can
 * never collide with a class another stylesheet defines; the legacy classes
 * the editor's elements also carry (.plan-editor, .editor-card)
 * keep their own rules in styles.css and are only refined here, scoped.
 *
 * Mobile first: one day on screen at a time, a 44px minimum for anything a
 * thumb presses, logical properties throughout so Persian mirrors for free,
 * and colours only from the design tokens so dark mode follows.
 */

.pe-root { display: flex; flex-direction: column; gap: 10px; }
/* The app's small buttons are 38px; in an editor used with a thumb, nothing is under 44. */
.pe-root button.small, .pe-footer button.small, .pe-dialog button, .pe-console-head button.small { min-height: 44px; }
.pe-root .pe-field { margin-block-end: 10px; }
.pe-hint { margin: 0; }
.pe-problem:empty, .pe-notice:empty { display: none; }

.pe-dates, .pe-more { border-radius: var(--radius-s); }
.pe-dates > summary, .pe-more > summary {
  cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 0.9rem; color: var(--text-dim); list-style-position: inside;
}
.pe-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 10px; }

/* ── the seven days ── */

.pe-week {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px;
  scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.pe-week::-webkit-scrollbar { display: none; }
.pe-day {
  flex: 0 0 auto; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 86px; max-width: 132px; min-height: 62px; padding: 8px 10px;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); box-shadow: none;
}
.pe-day-name { font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.pe-day-sum {
  font-size: 0.74rem; font-weight: 500; color: var(--text-dim); max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pe-day.pe-has { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--surface); }
.pe-day.pe-on {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent);
}
.pe-day.pe-on .pe-day-sum { color: color-mix(in srgb, var(--accent-text) 85%, transparent); }

/* ── one day ── */

.pe-panel { display: flex; flex-direction: column; gap: 10px; animation: pe-in 0.22s var(--ease) both; }
@keyframes pe-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.pe-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pe-panel-title { margin: 0; font-size: 1.2rem; }
.pe-day-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.pe-sections { display: flex; flex-direction: column; gap: 10px; }

.pe-section {
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); padding: 12px;
}
.pe-section.pe-empty {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-style: dashed; background: transparent; padding-block: 6px; padding-inline: 12px 6px; min-height: 56px;
}
.pe-empty .pe-slot-name { color: var(--text-dim); font-weight: 600; font-size: 0.95rem; }
.pe-section.pe-meal { background: var(--surface-2); margin: 0; box-shadow: var(--shadow-1); }
.pe-section.pe-meal.pe-locked { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.pe-section-head { display: flex; align-items: center; gap: 8px; margin-block-end: 8px; }
.pe-section-head .pe-slot-name { margin: 0; font-size: 1.02rem; flex: 1; }
.pe-custom-name { flex: 1; min-width: 0; font-weight: 700; }
.pe-time { width: auto; flex: 0 0 auto; min-width: 118px; font-variant-numeric: tabular-nums; }
.pe-icon { min-width: 44px; min-height: 44px; padding: 0; font-size: 1.25rem; line-height: 1; flex: 0 0 auto; }
.pe-lock {
  margin: 0 0 8px; display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent);
}
.pe-foods-label { margin-block-end: 6px; }

/* ── foods ── */

.pe-foods { display: flex; flex-direction: column; gap: 8px; }
.pe-no-foods { margin: 0; }
.pe-food {
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  border-radius: var(--radius-s); background: var(--surface); border: 1px solid var(--border);
}
.pe-food-main {
  display: grid; gap: 6px; align-items: center;
  grid-template-columns: minmax(0, 1fr) 76px minmax(96px, 128px) 44px;
  grid-template-areas: 'name qty unit del';
}
.pe-food-name { grid-area: name; min-width: 0; }
.pe-food-qty { grid-area: qty; text-align: center; }
.pe-food-unit { grid-area: unit; padding-inline: 8px; }
.pe-remove-food { grid-area: del; }
.pe-food-macros { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pe-mini { display: flex; flex-direction: column; gap: 2px; margin: 0; min-width: 0; }
.pe-mini-label { font-size: 0.7rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pe-mini input { min-height: 44px; padding: 8px; font-size: 0.9rem; text-align: center; }

@media (max-width: 460px) {
  /* A phone: the food's name gets the whole first line, its amount and unit the second. */
  .pe-food-main {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
    grid-template-areas: 'name name del' 'qty unit .';
  }
  .pe-food-macros { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.pe-add-food, .pe-add-exercise {
  width: 100%; min-height: 50px; margin-block: 8px 4px;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft); color: var(--accent); font-weight: 700; box-shadow: none;
}
.pe-add-food.pe-alt-add { min-height: 44px; margin-block: 4px 0; }
.pe-totals { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-block-start: 6px; }
.pe-chip {
  padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.pe-from-foods { font-size: 0.76rem; }
.pe-targets { margin-block-start: 8px; }
.pe-targets > p { margin: 0 0 6px; }
.pe-macro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0 8px; }
.pe-more { margin-block-start: 6px; }
.pe-alts { display: flex; flex-direction: column; gap: 8px; }
.pe-alt { padding: 8px; border-radius: var(--radius-s); border: 1px dashed var(--border-strong); display: flex; flex-direction: column; gap: 6px; }
.pe-alt-head { display: flex; align-items: center; gap: 8px; }
.pe-alt-name { flex: 1; min-width: 0; }
.pe-add-custom { width: 100%; border-style: dashed; }

/* ── workouts ── */

.pe-rest {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 28px 16px; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2);
}
.pe-rest > p { margin: 0; }
.pe-rest-title { font-size: 1.35rem; font-weight: 800; }
.pe-add-workout { min-height: 56px; min-width: min(280px, 100%); font-size: 1.05rem; margin-block-start: 8px; }
.pe-add-workout.pe-another { width: 100%; border-style: dashed; margin: 0; }
.pe-sessions { display: flex; flex-direction: column; gap: 12px; }
.pe-session { margin: 0; background: var(--surface-2); }
.pe-exercises-title { margin: 6px 0 8px; font-size: 1rem; }
.pe-exercises { display: flex; flex-direction: column; gap: 8px; }
.pe-exercise { margin: 0; padding: 10px; }
.pe-exercise-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-block-end: 6px; }
.pe-order { display: flex; gap: 4px; }
.pe-ex-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0 8px; }
.pe-session-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 10px; padding-block-start: 10px;
  border-block-start: 1px solid var(--border);
}

/* ── saving ── */

.pe-footer { display: flex; flex-direction: column; gap: 4px; margin-block-start: 10px; }
.pe-footer .pe-unsaved { align-self: flex-start; color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }
.pe-activate { margin-block-start: 16px; padding-block-start: 14px; border-block-start: 1px solid var(--border); }
.pe-card { padding-block-end: 12px; }

/* ── choosing days ── */

.pe-choose { display: flex; flex-direction: column; gap: 10px; }
.pe-choose > p { margin: 0; }
.pe-choose-days { display: flex; flex-direction: column; gap: 6px; }
.pe-check {
  display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 8px 12px; margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius-s); color: var(--text); font-size: 1rem; cursor: pointer;
}
.pe-check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); flex: 0 0 auto; }
.pe-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pe-check.pe-off { opacity: 0.55; cursor: not-allowed; }
.pe-choose-summary { margin: 0; font-weight: 600; min-height: 1.5em; }

/* ── the weekly plan and the console ── */

.pe-week-edit { margin-inline-start: auto; }
.pe-food-kcal { white-space: nowrap; }
.pe-console { display: flex; flex-direction: column; gap: 12px; max-width: 780px; }
.pe-console-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pe-console-head h2 { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .pe-panel { animation: none; }
}
