/* NutriPlan — editorial
 * ==========================================================================
 *
 * Layout borrowed from editorial print: a fixed side rail, a scrolling body,
 * heavy rules, and type set larger than feels comfortable. Arabic script rewards
 * scale -- it is drawn to be seen at size, and almost no Arabic interface does
 * that.
 *
 * TWO RULES RUN THROUGH THE WHOLE FILE
 *
 * 1. No `left` or `right`. The page mirrors between Arabic and English at
 *    runtime; physical directions break the moment it flips. Logical properties
 *    only -- inline-start, padding-inline, border-block-end.
 *
 * 2. Every hover effect sits inside `@media (hover: hover)`. A phone has no
 *    hover: a `:hover` rule fires on tap and STICKS until you touch something
 *    else, so a chip you tapped stays lit and reads as selected when it is not.
 *    Touch gets `:active`, which releases.
 */

:root {
  /* Ink and bone, one accent. Fewer colours used harder. */
  --ink:      #0B0D10;
  --panel:    #12161B;
  --raised:   #1A2027;
  --rule:     #2A323C;
  --bone:     #F2F0EA;
  --muted:    #8B95A1;

  /* Sumac: warmer and more editorial than a brand green, and it sits next to
     Arabic text without fighting it. */
  --accent:   #E4593F;
  --accent-2: #FF7454;
  --gold:     #C9A227;
  --danger:   #E4635A;

  --display: "Readex Pro", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --body:    "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --rail: 280px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Latin figures inside Arabic, so numbers match the generated PDF. */
[dir="rtl"] { font-feature-settings: "lnum" 1; }

/* Arabic letters join. Tracking them apart breaks the joins and makes the script
   look misspelt, so it is cleared anywhere a heading might inherit it. */
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3,
[dir="rtl"] .eyebrow, [dir="rtl"] label { letter-spacing: 0; }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
}
::selection { background: var(--accent); color: var(--ink); }

/* ── topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; inset-block-start: 0; z-index: 40;
  min-block-size: 64px;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
  background: color-mix(in srgb, var(--ink) 90%, transparent);
  backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--rule);
}
#languageToggle {
  font: inherit; font-family: var(--mono); font-size: 0.78rem;
  letter-spacing: 0.08em;
  padding: 0.4rem 0.9rem;
  background: transparent; color: var(--muted);
  border: 1px solid var(--rule); cursor: pointer;
  transition: color 200ms, border-color 200ms;
}
@media (hover: hover) {
  #languageToggle:hover { color: var(--accent); border-color: var(--accent); }
}

.logo { display: flex; text-decoration: none; color: inherit; align-items: center; gap: 0.6rem; font-weight: 600; }
.logo-mark {
  inline-size: 30px; block-size: 30px;
  background: var(--accent); color: var(--ink);
  display: grid; place-items: center; font-weight: 700;
  transition: transform 400ms var(--ease), background-color 200ms;
}
@media (hover: hover) {
  .logo:hover .logo-mark { transform: rotate(-8deg) scale(1.08); background: var(--accent-2); }
}

/* ── hero ──────────────────────────────────────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
  padding: clamp(2.5rem, 8vw, 6rem) clamp(1rem, 4vw, 2.5rem);
  max-inline-size: 1400px; margin-inline: auto;
}
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }

.eyebrow {
  font-family: var(--mono); font-size: 0.75rem;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 1.2rem;
  display: flex; align-items: center; gap: 0.6rem;
}
.eyebrow::before {
  content: ""; inline-size: 34px; block-size: 2px; background: var(--accent);
  transform-origin: inline-start;
  animation: rule-in 900ms var(--ease) both;
}
@keyframes rule-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.hero h1 {
  font-family: var(--display);
  /* Capped well below the previous 6rem. Arabic words are long and unhyphenated,
     so a size that fits an English headline overflows its column here and breaks
     mid-word -- which in Arabic reads as a spelling error, not a line break. */
  font-size: clamp(2rem, 1.1rem + 3.4vw, 3.8rem);
  line-height: 1.25; font-weight: 600;
  margin: 0 0 1.4rem;
  /* `balance` measures in a way that mangles Arabic; `pretty` only tidies the
     last line and leaves the joins alone. */
  text-wrap: pretty;
  overflow-wrap: break-word;
}
.hero h1 em {
  font-style: normal; color: var(--accent);
  position: relative; white-space: nowrap;
}
.hero h1 em::after {
  content: ""; position: absolute; inset-inline: 0; inset-block-end: 0.06em;
  block-size: 3px; background: var(--accent);
  transform-origin: inline-start;
  animation: rule-in 1.1s 400ms var(--ease) both;
}
.lead {
  color: var(--muted);
  font-size: clamp(1rem, 0.9rem + 0.4vw, 1.15rem);
  max-inline-size: 46ch; margin: 0 0 2rem;
}

/* ── the plate grid: the signature ─────────────────────────────────────── */
.plate {
  border: 1px solid var(--rule);
  background: linear-gradient(160deg, var(--panel), var(--ink));
  padding: 1.1rem;
  position: relative;
}
/* Corner register marks, borrowed from print. Cheap, and it reads as made. */
.plate::before, .plate::after {
  content: ""; position: absolute;
  inline-size: 14px; block-size: 14px;
  border: 2px solid var(--accent); opacity: 0.85;
}
.plate::before {
  inset-block-start: -1px; inset-inline-start: -1px;
  border-inline-end: 0; border-block-end: 0;
}
.plate::after {
  inset-block-end: -1px; inset-inline-end: -1px;
  border-inline-start: 0; border-block-start: 0;
}

.plate-head {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding-inline: 0.2rem; margin-block-end: 0.9rem;
  font-family: var(--mono); font-size: 0.78rem; color: var(--muted);
}
#plateCountry {
  font-family: var(--display); font-size: 1.05rem;
  color: var(--accent); font-weight: 600;
}

#plateGrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
@media (max-width: 640px) { #plateGrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.plate-cell {
  background: var(--raised);
  padding: 0.5rem 0.4rem;
  min-block-size: 64px;
  font-size: 0.78rem; line-height: 1.35;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  animation: cell-in 500ms var(--ease) backwards;
  transition: background-color 180ms, color 180ms, transform 220ms var(--ease);
}
.plate-cell.lead { color: var(--bone); }

/* The stagger lives here rather than in an inline style: the Content Security
   Policy is `style-src 'self'`, and setting it per element inline made the
   browser refuse all 28 of them. nth-child gives the same cascade for free. */
.plate-cell:nth-child(4n+1) { animation-delay: 0ms; }
.plate-cell:nth-child(4n+2) { animation-delay: 40ms; }
.plate-cell:nth-child(4n+3) { animation-delay: 80ms; }
.plate-cell:nth-child(4n+4) { animation-delay: 120ms; }
.plate-cell:nth-child(n+9)  { animation-delay: 160ms; }
.plate-cell:nth-child(n+17) { animation-delay: 220ms; }
.plate-cell:nth-child(n+25) { animation-delay: 280ms; }
@keyframes cell-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
/* Every cell answers the pointer, so the grid feels alive rather than painted. */
@media (hover: hover) {
  .plate-cell:hover {
    background: var(--accent); color: var(--ink);
    transform: scale(1.09); position: relative; z-index: 2;
  }
}
.plate-cell:active { background: var(--accent); color: var(--ink); }

/* ── buttons ───────────────────────────────────────────────────────────── */
.button {
  font: inherit; font-weight: 600;
  padding: 0.8rem 1.7rem;
  border: 1px solid var(--rule);
  background: transparent; color: var(--bone);
  cursor: pointer; position: relative; isolation: isolate;
  transition: color 220ms, border-color 220ms, transform 140ms var(--ease);
}
/* A wipe that fills from the reading edge, so its direction follows the page. */
.button::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--accent);
  transform: scaleX(0); transform-origin: inline-start;
  transition: transform 300ms var(--ease);
  pointer-events: none;
}
@media (hover: hover) {
  .button:hover { color: var(--ink); border-color: var(--accent); }
  .button:hover::before { transform: scaleX(1); }
}
.button:active { transform: translateY(1px); }
.button.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.button.primary::before { background: var(--accent-2); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── workspace: fixed rail, scrolling form ─────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  max-inline-size: 1400px; margin-inline: auto;
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2.5rem) 5rem;
}
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .rail { display: none; }
}

.rail { position: sticky; inset-block-start: 5.5rem; align-self: start; }
.rail-line { display: none; }
#progress { list-style: none; margin: 0; padding: 0; }
#progress li {
  font-family: var(--mono); font-size: 0.88rem;
  color: var(--muted);
  padding: 0.6rem 0;
  border-block-end: 1px solid var(--rule);
  display: flex; align-items: center; gap: 0.7rem;
  transition: color 260ms, padding-inline-start 260ms var(--ease);
}
#progress li::before {
  content: ""; inline-size: 0; block-size: 2px; background: var(--accent);
  transition: inline-size 300ms var(--ease);
}
#progress li.active { color: var(--bone); padding-inline-start: 0.2rem; }
#progress li.active::before { inline-size: 22px; }
@media (hover: hover) { #progress li:hover { color: var(--bone); } }

/* ── form ──────────────────────────────────────────────────────────────── */
.planner { display: grid; }

.step {
  padding: clamp(1.8rem, 4vw, 3rem) 0;
  border-block-end: 1px solid var(--rule);
  scroll-margin-block-start: 6rem;
}
.step:first-child { padding-block-start: 0; }

.step h2 {
  font-family: var(--display);
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.4rem);
  font-weight: 600; margin: 0;
  position: relative; display: inline-block;
}
/* The heading rule draws itself as the step scrolls into view. */
.step h2::after {
  content: ""; position: absolute; inset-inline: 0; inset-block-end: -6px;
  block-size: 2px; background: var(--accent);
  transform: scaleX(0); transform-origin: inline-start;
  transition: transform 600ms var(--ease);
}
.step.seen h2::after { transform: scaleX(1); }

.step-note { color: var(--muted); font-size: 0.92rem; margin: 0.8rem 0 1.6rem; }

label {
  display: block;
  font-family: var(--mono); font-size: 0.72rem;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
  margin-block: 1.1rem 0.4rem;
}
label.check {
  display: flex; gap: 0.7rem; align-items: flex-start;
  font-family: var(--body); font-size: 0.95rem;
  text-transform: none; letter-spacing: 0; color: var(--bone);
  cursor: pointer; padding: 0.75rem; margin-block-start: 1rem;
  border: 1px solid var(--rule);
  transition: border-color 200ms, background-color 200ms;
}
@media (hover: hover) {
  label.check:hover { border-color: var(--accent); background: var(--panel); }
}
label.check input {
  accent-color: var(--accent);
  inline-size: 1.05rem; block-size: 1.05rem; margin-block-start: 0.15rem;
}

input[type="number"], input[type="email"], select {
  font: inherit; color: var(--bone);
  background: var(--panel);
  border: 1px solid var(--rule); border-radius: 0;
  padding: 0.75rem 0.85rem; inline-size: 100%;
  transition: border-color 200ms, background-color 200ms;
}
input[type="number"] { font-family: var(--mono); }
@media (hover: hover) { input:hover, select:hover { border-color: var(--muted); } }
input:focus, select:focus { border-color: var(--accent); background: var(--raised); }
input[aria-invalid="true"] { border-color: var(--danger); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 1rem;
}

/* ── chips ─────────────────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.chip {
  font: inherit; font-size: 0.86rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--rule);
  background: transparent; color: var(--muted);
  cursor: pointer; position: relative; isolation: isolate;
  transition: color 200ms, border-color 200ms, transform 160ms var(--ease);
}
.chip::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--accent);
  transform: scaleY(0); transform-origin: bottom;
  transition: transform 240ms var(--ease);
  /* Without this the decoration swallows the click and the chip never toggles --
     which fails silently: the form submits with no allergies and no training
     days, and nothing anywhere says so. */
  pointer-events: none;
}
@media (hover: hover) {
  .chip:hover { color: var(--bone); border-color: var(--accent); transform: translateY(-2px); }
}
.chip:active { transform: scale(0.97); }

/* `.selected` is how app.js reads which chips are on. Styled here, never
   renamed -- swapping it makes every selection silently read as empty. */
.chip.selected { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.chip.selected::before { transform: scaleY(1); }

/* ── disclaimer, notices, loading ──────────────────────────────────────── */
.disclaimer {
  border-inline-start: 3px solid var(--gold);
  background: var(--panel);
  padding: 1rem 1.1rem; margin-block-end: 1rem;
  max-block-size: 200px; overflow-y: auto;
  font-size: 0.9rem; color: var(--muted);
}
.disclaimer strong { color: var(--gold); display: block; margin-block-end: 0.4rem; }

#notice[hidden] { display: none; }
#notice {
  border: 1px solid var(--danger); border-inline-start-width: 4px;
  background: color-mix(in srgb, var(--danger) 12%, var(--ink));
  padding: 1rem 1.2rem; margin: 1rem 0; font-size: 0.94rem;
  animation: fade-up 400ms var(--ease);
}
@keyframes fade-up { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.loading[hidden] { display: none; }
.loading {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  margin-block-start: 1.2rem; color: var(--muted); font-size: 0.92rem;
}
.loading small { inline-size: 100%; opacity: 0.75; font-size: 0.82rem; }
.spinner {
  inline-size: 16px; block-size: 16px; flex: none;
  border: 2px solid var(--rule); border-block-start-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── results ───────────────────────────────────────────────────────────── */
#results[hidden] { display: none; }
#results {
  /* A sibling of .workspace, not a child, so it inherits none of the page
     margins -- it ran edge to edge and the day cards looked cropped. */
  max-inline-size: 1400px;
  margin: 3rem auto 0;
  padding-inline: clamp(1rem, 4vw, 2.5rem);
  animation: fade-up 500ms var(--ease);
}
@media (min-width: 981px) {
  /* Line the results up with the form column rather than the rail, so the eye
     follows one edge from the questions down to the answers. */
  #results { padding-inline-start: calc(clamp(1rem, 4vw, 2.5rem) + var(--rail) + clamp(1.5rem, 4vw, 4rem)); }
}
#results h2 {
  font-family: var(--display);
  font-size: clamp(1.8rem, 1.2rem + 2.4vw, 3rem);
  margin: 0 0 1.5rem;
}
#results h3 {
  font-family: var(--mono); font-size: 0.75rem;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); font-weight: 400;
  margin: 2.2rem 0 0.9rem;
  padding-block-end: 0.5rem; border-block-end: 1px solid var(--rule);
}

/* One-pixel gaps over a rule colour: a hairline grid, no double borders. */
.target-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px; border: 1px solid var(--rule);
}
.metric {
  background: var(--panel); outline: 1px solid var(--rule);
  padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: 0.2rem;
  transition: background-color 220ms;
}
.metric span {
  font-family: var(--mono); font-size: 0.68rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}
.metric strong {
  font-family: var(--mono); font-weight: 500;
  font-size: clamp(1.3rem, 1rem + 1.2vw, 1.9rem);
}
@media (hover: hover) { .metric:hover { background: var(--raised); } }

.days {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1px;
  /* No background here: seven cards in a three-column grid leave two empty
     cells, and a background behind the gaps painted them as grey blocks. */
  border: 1px solid var(--rule);
}
.day-card {
  background: var(--panel);
  padding: 1.1rem 1.2rem;
  /* The 1px gap plus an outline reproduces the hairline without needing a
     colour behind the whole grid. */
  outline: 1px solid var(--rule);
  transition: background-color 240ms;
}
.day-card h3 {
  font-family: var(--display); font-size: 1.05rem; font-weight: 600;
  color: var(--bone); letter-spacing: 0; text-transform: none;
  margin: 0 0 0.8rem; padding: 0; border: 0;
  transition: color 240ms;
}
@media (hover: hover) {
  .day-card:hover { background: var(--raised); }
  .day-card:hover h3 { color: var(--accent); }
}

.meal {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 0.8rem; padding-block: 0.45rem;
  border-block-end: 1px dashed color-mix(in srgb, var(--rule) 70%, transparent);
  font-size: 0.9rem;
  transition: padding-inline-start 200ms var(--ease), color 200ms;
}
.meal:last-child { border-block-end: 0; }
.meal small { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); flex: none; }
@media (hover: hover) { .meal:hover { padding-inline-start: 0.4rem; color: var(--accent-2); } }

.shopping { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; }
.aisle h4 {
  font-family: var(--mono); font-size: 0.72rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 0.6rem; padding-block-end: 0.4rem;
  border-block-end: 1px solid var(--rule);
}
.aisle ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.aisle li {
  font-size: 0.88rem; color: var(--muted);
  transition: padding-inline-start 180ms var(--ease), color 180ms;
}
@media (hover: hover) { .aisle li:hover { color: var(--bone); padding-inline-start: 0.35rem; } }

.blocked {
  border-inline-start: 4px solid var(--danger);
  background: var(--panel); padding: 1.2rem 1.4rem;
}
.blocked ul { margin: 0.6rem 0 0; padding-inline-start: 1.1rem; color: var(--muted); }

.actions {
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center;
  margin-block-start: 2rem; padding-block-start: 1.5rem;
  border-block-start: 1px solid var(--rule);
}
.actions input[type="email"] { inline-size: min(280px, 60vw); }

footer {
  border-block-start: 1px solid var(--rule);
  padding: 2rem clamp(1rem, 4vw, 2.5rem) 3rem;
  max-inline-size: 1400px; margin-inline: auto;
  color: var(--muted); font-size: 0.84rem;
}

/* ── motion off ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* app.js toggles `.submit` disabled during a request. Without a rule of its own
   the button gave no feedback that anything was happening -- and on a cold start
   that silence lasts fifty seconds. */
.submit { margin-block-start: 1.4rem; min-inline-size: 200px; }
.submit:disabled { opacity: 0.5; cursor: wait; }
.submit:disabled::before { transform: scaleX(0); }

/* The send result sits with the button that produced it. */
#emailStatus { font-size: 0.88rem; color: var(--muted); inline-size: 100%; }
#emailStatus.failed { color: var(--danger); }

/* A disabled action must look unavailable, or an impatient user keeps pressing
   it. `wait` rather than `not-allowed`: the work is in progress, not refused. */
#pdf:disabled, #send:disabled { opacity: 0.6; cursor: wait; }
#pdf:disabled::before, #send:disabled::before { transform: none; }
