:root {
  --bg: #f4f8f1;
  --card: #ffffff;
  --text: #1f2a1c;
  --muted: #5f6d59;
  --line: #dfe8d8;
  --green: #2e7d32;
  --green-2: #43a047;
  --green-soft: #e6f2e2;
  --red: #c62828;
  --red-soft: #fdecea;
  --amber-soft: #fff6e0;
  --shadow: 0 2px 10px rgba(30, 60, 20, .07);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121711; --card: #1b2219; --text: #e5eee1; --muted: #9fb197; --line: #2d3a29;
    --green: #66bb6a; --green-2: #81c784; --green-soft: #1f3320; --red: #ef7070; --red-soft: #3a1c1c;
    --amber-soft: #3a3016; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
}
[dir="rtl"] body { font-family: Tahoma, "Segoe UI", Arial, sans-serif; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--green); }
.top-actions { display: flex; gap: 8px; }
.lang-btn, .look-btn {
  border: 1px solid var(--line); background: var(--green-soft); color: var(--green);
  padding: 6px 12px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.subtitle { color: var(--muted); margin: 4px 0 16px; }

.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 16px; flex-wrap: wrap; }
.steps li {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: .92rem;
}
.steps li span {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--line); color: var(--text); font-size: .8rem; font-weight: 700;
}
.steps li.active { border-color: var(--green); color: var(--green); }
.steps li.active span { background: var(--green); color: #fff; }
.steps li.done { cursor: pointer; }
.steps li.done span { background: var(--green-soft); color: var(--green); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
h2 { margin: 0 0 8px; font-size: 1.25rem; }
h3 { margin: 0; font-size: 1.1rem; }
.hint { color: var(--muted); font-size: .92rem; margin: 6px 0; }
.warn { background: var(--amber-soft); padding: 8px 12px; border-radius: 10px; font-size: .92rem; }
.error { color: var(--red); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; }
.grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .92rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .92rem; margin-bottom: 4px; padding: 0; }
input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-2); outline-offset: 1px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--green); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex-direction: row; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; font-weight: 500; background: var(--bg);
}
.seg input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--green-2); }
.custom-box { background: var(--green-soft); padding: 12px; border-radius: 10px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: flex-end; }
.btn {
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:hover { border-color: var(--green-2); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--red); }

/* targets */
.targets { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; margin: 8px 0; }
.targets .big {
  flex: 1 1 140px; background: var(--green-soft); border-radius: 12px; padding: 12px 16px;
  display: flex; flex-direction: column;
}
.targets .big span { color: var(--muted); font-size: .85rem; font-weight: 600; }
.targets .big b { font-size: 2rem; color: var(--green); line-height: 1.1; }
.targets .big small { color: var(--muted); }
.targets .small { flex: 1 1 200px; display: flex; flex-direction: column; justify-content: center; gap: 4px; font-size: .9rem; color: var(--muted); }
#targetsPreview h3 { margin-top: 16px; }

/* chips */
.chip-tools { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.chip-tools input { flex: 1 1 220px; }
.chip-legend { font-size: .85rem; color: var(--muted); }
.cat { margin: 6px 0; border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.cat summary { cursor: pointer; font-weight: 700; padding: 6px 0; font-size: .95rem; }
.cat summary small { color: var(--muted); font-weight: 500; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 10px; }
.chip {
  font: inherit; font-size: .9rem; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.chip.like { background: var(--green-soft); border-color: var(--green); color: var(--green); font-weight: 600; }
.chip.dislike { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 600; text-decoration: line-through; }

/* plan */
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.plan .card { margin: 0; }
.day-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pill { font-size: .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; color: var(--muted); }
.pill.strong { background: var(--green); color: #fff; border-color: var(--green); }
.slot { border-top: 1px dashed var(--line); padding: 10px 0; }
.slot-h { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.slot.meal .slot-h b { color: var(--green); }
.slot.snack .slot-h b { color: #b26a00; }
.slot.changed { background: var(--amber-soft); border-radius: 10px; padding: 10px; margin: 4px -10px; animation: flash 1.2s ease; }
@keyframes flash { from { box-shadow: 0 0 0 3px #f9a825; } to { box-shadow: 0 0 0 0 transparent; } }
.slot ul { list-style: none; padding: 0; margin: 6px 0 0; }
.slot li { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 3px 0; font-size: .93rem; }
.slot li .amt { font-weight: 700; white-space: nowrap; }
.slot li small { grid-column: 1 / -1; color: var(--muted); font-size: .78rem; }
.cheat { margin: 6px 0 0; }

/* edit panel */
.edit-card { border-color: var(--green-2); }
.edit-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0; }
.edit-list { list-style: none; padding: 0; margin: 12px 0 0; }
.edit-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; background: var(--bg);
}
.edit-list li.empty { color: var(--muted); justify-content: center; }
.edit-list .x { border: 0; background: none; color: var(--red); font-size: 1.3rem; cursor: pointer; line-height: 1; }

.notes ul { margin: 0; padding-inline-start: 20px; }
.notes li { margin: 4px 0; }
.disclaimer { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 24px; }

/* AI (ChatGPT) boxes */
.ai-box {
  border: 1px dashed #8e6bd8; background: rgba(142, 107, 216, .07); border-radius: 12px;
  padding: 12px; margin: 10px 0;
}
.ai-box .actions { margin-top: 8px; }
.btn.ai { background: #7c4dff; border-color: #7c4dff; color: #fff; }
.btn.ai:hover { background: #9575ff; }
.btn.ai:disabled { opacity: .6; cursor: wait; }
.ai-out { margin-top: 10px; font-size: .92rem; }
.ai-out ul { margin: 6px 0 0; padding-inline-start: 20px; }
.ai-out .err { color: var(--red); font-weight: 600; }
.ai-tag { display: inline-block; font-size: .72rem; font-weight: 700; color: #7c4dff; border: 1px solid #7c4dff; border-radius: 999px; padding: 0 6px; margin-inline-start: 6px; vertical-align: middle; }
.or-line { text-align: center; color: var(--muted); font-size: .85rem; margin: 4px 0; }
.ai-ask { padding: 10px 0; border-bottom: 1px solid var(--line); }
.ai-ask .lk-item { border-bottom: 1px dashed var(--line); }
.lk-item .save { grid-column: 1 / -1; justify-self: start; font-size: .82rem; padding: 4px 10px; }

/* confirm dialog (replaces the browser's alert box) */
dialog.confirm {
  width: min(400px, calc(100vw - 32px)); border: 0; border-radius: 18px; padding: 24px 22px 18px;
  background: var(--card); color: var(--text); text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog.confirm[open] { animation: pop .18s ease-out; }
dialog.confirm::backdrop { background: rgba(15, 25, 12, .45); backdrop-filter: blur(3px); }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cf-icon {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center;
  font-size: 1.6rem; background: var(--red-soft);
}
dialog.confirm h2 { font-size: 1.2rem; margin: 0 0 6px; }
dialog.confirm p { color: var(--muted); margin: 0 0 20px; font-size: .95rem; }
.cf-actions { display: flex; gap: 10px; }
.cf-actions .btn { flex: 1; padding: 11px 14px; }
.btn.danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-solid:hover { filter: brightness(1.08); }

/* calorie lookup dialog */
dialog.lookup {
  width: min(680px, calc(100vw - 24px)); max-height: 86vh; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); padding: 0;
}
dialog.lookup::backdrop { background: rgba(0, 0, 0, .4); }
.lk-head { position: sticky; top: 0; background: var(--card); padding: 16px; border-bottom: 1px solid var(--line); }
.lk-head .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.lk-head .row button { border: 0; background: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); }
.lk-body { padding: 8px 16px 16px; overflow: auto; }
.lk-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lk-item .nm { font-weight: 600; }
.lk-item .per { color: var(--muted); font-size: .82rem; }
.lk-item .kc { text-align: end; font-weight: 700; color: var(--green); white-space: nowrap; }
.lk-item .calc { grid-column: 1 / -1; display: flex; flex-direction: row; flex-wrap: wrap; font-weight: 500; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.lk-item .calc input { width: 90px; padding: 4px 8px; }
.lk-count { color: var(--muted); font-size: .85rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2); z-index: 20;
}

@media (max-width: 520px) {
  .plan { grid-template-columns: 1fr; }
  .wrap { padding: 12px 16px; }
  .card { padding: 14px; }
  .targets .big b { font-size: 1.6rem; }
  .brand span { display: none; }
}
@media print {
  .top, .steps, .no-print, .disclaimer, .subtitle, #step1, #step2, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
  .plan { grid-template-columns: 1fr 1fr; }
  .slot.changed { background: none; }
}
