/* פאזל הבישול — warm kitchen palette, mobile-first, RTL, light + dark. */
:root {
  --bg: #F6F1E7;
  --surface: #FFFDF8;
  --surface-2: #F0E8DA;
  --ink: #2B2620;
  --muted: #7A6E60;
  --line: #E3D9C8;
  --accent: #C1582A;
  --accent-ink: #9E4620;
  --accent-soft: #F6E1D4;
  --olive: #6F7F3E;
  --olive-soft: #E6EAD3;
  --amber: #C98A1B;
  --danger: #B23A2E;
  --danger-soft: #F7DDD8;
  --ok: #4E7D48;
  --ok-soft: #DDEBD9;
  --shadow: 0 1px 2px rgba(43, 38, 32, .06), 0 10px 28px -14px rgba(43, 38, 32, .25);
  --role-protein-bg: #F3D9CF; --role-protein-ink: #8A3A22;
  --role-grain-bg: #F4E6C2;   --role-grain-ink: #7A5A10;
  --role-cooked-bg: #DCE6C8;  --role-cooked-ink: #3F5A22;
  --role-fresh-bg: #D3EBD3;   --role-fresh-ink: #23602A;
  --role-pickled-bg: #E4D8EC; --role-pickled-ink: #5A3D7A;
  --role-spread-bg: #EADCCB;  --role-spread-ink: #6B4A2B;
  --font: "Rubik", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E1A16; --surface: #28231E; --surface-2: #332C25; --ink: #F1EAE0; --muted: #A69A8A; --line: #3F372F;
    --accent: #E07A4A; --accent-ink: #F2A47C; --accent-soft: #3D2A20;
    --olive: #A6B36E; --olive-soft: #2F3324; --amber: #E0A63A;
    --danger: #E06A5E; --danger-soft: #45251F; --ok: #8DBE84; --ok-soft: #26332A;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -14px rgba(0,0,0,.7);
    --role-protein-bg: #4A2A22; --role-protein-ink: #F2B8A5;
    --role-grain-bg: #45391C;   --role-grain-ink: #F1D48A;
    --role-cooked-bg: #2E3A22;  --role-cooked-ink: #C4D89E;
    --role-fresh-bg: #223A26;   --role-fresh-ink: #A9DFAF;
    --role-pickled-bg: #362A40; --role-pickled-ink: #D6BFEA;
    --role-spread-bg: #3E3024;  --role-spread-ink: #E3C7A8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; text-wrap: balance; }
p { margin: 0 0 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.noscript { padding: 24px; text-align: center; }

/* ── header ─────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; }
.brand h1 { font-size: 18px; font-weight: 700; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12.5px;
}
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-chip[data-status="saved"] .dot { background: var(--ok); }
.sync-chip[data-status="syncing"] .dot { background: var(--amber); animation: pulse 1s infinite; }
.sync-chip[data-status="error"] .dot { background: var(--danger); }
.sync-chip[data-status="error"] { color: var(--danger); border-color: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 520px) { .header-actions .btn span.long { display: none; } .brand h1 { font-size: 16px; } }

/* ── layout ─────────────────────────────────────────────────────────────── */
.view { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.section { margin: 0 0 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.section-head h2 { font-size: 20px; font-weight: 700; }
.section-head h3 { font-size: 16px; font-weight: 700; }
.hint { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.two-col { display: grid; gap: 16px; }
@media (min-width: 880px) { .two-col { grid-template-columns: 1.3fr 1fr; align-items: start; } }
@media (max-width: 879px) { .two-col.plate-first > :last-child { order: -1; } }

/* ── tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px -14px rgba(0,0,0,.35);
}
.tabs button {
  border: 0; background: none; color: var(--muted); display: grid; place-items: center; gap: 2px;
  font-size: 12px; font-weight: 500; padding: 6px 4px;
}
.tabs button .ico { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent-ink); }
.tabs button.on .ico { transform: translateY(-1px); }
@media (min-width: 720px) {
  .tabs { inset-inline: 50%; transform: translateX(50%); width: 520px; bottom: 14px; border-radius: 999px; border: 1px solid var(--line); box-shadow: var(--shadow); height: 60px; padding-bottom: 0; }
  .tabs button { border-radius: 999px; }
}

/* ── buttons & chips ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 500; text-decoration: none; min-height: 40px; box-shadow: 0 1px 0 rgba(0,0,0,.03);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.95); background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent-ink); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: 13.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; width: 36px; height: 36px; display: inline-grid; place-items: center; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin-inline: -16px; padding-inline: 16px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; white-space: nowrap; min-height: 36px;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.chip.small { padding: 4px 9px; min-height: 28px; font-size: 12.5px; }
.chip.olive.on { background: var(--olive-soft); border-color: var(--olive); color: var(--olive); }

/* picker filters */
.filters { display: grid; gap: 6px; margin: 10px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.fgroup { display: grid; grid-template-columns: 78px minmax(0, 1fr); align-items: center; gap: 8px; }
.flabel { font-size: 12.5px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.fgroup .chips.scroll { margin-inline: 0; padding-inline: 0; }
.chip.busy { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.chip.busy.on { color: var(--accent-ink); text-decoration: none; }
.muted { color: var(--muted); }

/* home: inventory grouped by plate role */
.inv-group { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.inv-group h3 { font-size: 15px; font-weight: 700; display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.inv-group.missing { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: color-mix(in srgb, var(--danger-soft) 35%, var(--surface)); }
.inv-empty { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; color: var(--danger); font-size: 14px; }
.inv-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line-soft, var(--line)); }
.inv-row:first-of-type { border-top: 0; }
.inv-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.inv-main .name { font-weight: 600; }
.inv-main .meta { color: var(--muted); font-size: 12.5px; }
.inv-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.notice.row { align-items: center; }

/* ── badges ─────────────────────────────────────────────────────────────── */
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); line-height: 1.5;
}
.badge.protein { background: var(--role-protein-bg); color: var(--role-protein-ink); }
.badge.grain { background: var(--role-grain-bg); color: var(--role-grain-ink); }
.badge.cooked_vegetable { background: var(--role-cooked-bg); color: var(--role-cooked-ink); }
.badge.fresh_vegetable { background: var(--role-fresh-bg); color: var(--role-fresh-ink); }
.badge.fermented_pickled { background: var(--role-pickled-bg); color: var(--role-pickled-ink); }
.badge.spread { background: var(--role-spread-bg); color: var(--role-spread-ink); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.status { background: var(--olive-soft); color: var(--olive); }
.badge.status.finish { background: #F7E7C7; color: #8A5A05; }

/* ── cards ──────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  position: relative; text-align: start; display: flex; flex-direction: column; gap: 8px;
  padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  box-shadow: 0 1px 0 rgba(0,0,0,.02); min-height: 108px; width: 100%;
}
button.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card.selected { border-color: var(--accent); background: var(--accent-soft); }
.card .title { font-weight: 700; font-size: 15.5px; line-height: 1.3; }
.card .meta { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.card .corner { position: absolute; top: 8px; inset-inline-start: 8px; }
.card .pill-corner { position: absolute; top: 8px; inset-inline-end: 8px; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* plan item card */
.plan-item { display: grid; gap: 8px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.plan-item.prepared { background: color-mix(in srgb, var(--olive-soft) 55%, var(--surface)); }
.plan-item.conflict { border-color: var(--danger); }
.plan-item .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.plan-item .title { font-weight: 700; font-size: 16px; }
.plan-item .tool { font-size: 13px; color: var(--muted); white-space: nowrap; }
.plan-item.conflict .tool { color: var(--danger); font-weight: 600; }
.plan-item .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── puzzles ────────────────────────────────────────────────────────────── */
.puzzle { padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.puzzle h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.plate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid transparent; font-size: 13px; }
.tile .t-name { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.tile .t-foods { color: var(--muted); font-size: 12px; line-height: 1.35; }
.tile.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.tile.missing { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.tile.optional { opacity: .8; }
.kitchen { display: grid; gap: 6px; }
.tool-row { display: grid; grid-template-columns: 96px 1fr; gap: 8px; align-items: center; font-size: 13.5px; }
.tool-row .t-name { color: var(--muted); font-weight: 500; }
.tool-row .slots { display: flex; gap: 6px; flex-wrap: wrap; }
.slot { padding: 3px 10px; border-radius: 8px; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; min-width: 64px; text-align: center; }
.slot.filled { border-style: solid; background: var(--surface-2); color: var(--ink); font-weight: 500; }
.slot.conflict { border-style: solid; background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.conflicts { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13.5px; }
.effort-line { color: var(--muted); font-size: 13.5px; margin-top: 10px; }

/* ── forms ──────────────────────────────────────────────────────────────── */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .field .label { font-weight: 600; font-size: 14px; }
.field .sub { color: var(--muted); font-size: 12.5px; }
.input, input[type="text"], input[type="search"], input[type="password"], input[type="number"], textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; direction: ltr; text-align: left; }
textarea.he { font-family: inherit; direction: rtl; text-align: start; font-size: 15px; min-height: 70px; }
.field.error .input, .field.error input, .field.error textarea { border-color: var(--danger); }
.err { color: var(--danger); font-size: 13px; }
.search { display: flex; gap: 8px; align-items: center; }
.search input { flex: 1; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: none; padding: 8px 14px; font-weight: 500; color: var(--muted); }
.segmented button.on { background: var(--accent-soft); color: var(--accent-ink); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.stepper .val { min-width: 64px; text-align: center; font-size: 13.5px; color: var(--muted); }

/* ── sheet ──────────────────────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; display: grid; align-items: end; justify-items: center; background: rgba(30, 24, 18, .45); }
.sheet-panel {
  width: 100%; max-height: 92dvh; overflow: auto; background: var(--bg); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); } }
@media (prefers-reduced-motion: reduce) { .sheet-panel { animation: none; } }
@media (min-width: 720px) {
  .sheet { align-items: center; padding: 24px; }
  .sheet-panel { max-width: 680px; border-radius: 20px; max-height: 88dvh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; position: sticky; top: -12px; background: var(--bg); padding: 8px 0; z-index: 1; }
.sheet-head h2 { font-size: 19px; font-weight: 700; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.sheet-foot .spacer { flex: 1; }
.detail-list { display: grid; gap: 6px; font-size: 14.5px; }
.detail-list .k { color: var(--muted); }
.detail-list .v { font-weight: 500; }

/* ── misc ───────────────────────────────────────────────────────────────── */
.empty { padding: 26px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
.empty .big { font-size: 34px; line-height: 1; margin-bottom: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 60; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); font-size: 14px; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--danger-soft); color: var(--danger); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; direction: ltr; unicode-bidi: embed; }
.options-list { display: grid; gap: 14px; }
.option { padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); display: grid; gap: 10px; }
.option .opt-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.option .opt-label { font-weight: 700; font-size: 16px; }
.mini-list { display: grid; gap: 6px; }
.mini-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.mini-item .name { font-weight: 600; }
.mini-item .tool { color: var(--muted); font-size: 12.5px; }
.mini-item.prepared { background: var(--olive-soft); }
.q { margin-bottom: 14px; }
.q .q-title { font-weight: 600; margin-bottom: 8px; font-size: 15px; }
.fab-row { position: sticky; bottom: calc(var(--tabbar-h) + 10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.fab-row .btn { box-shadow: var(--shadow); }

/* 404 */
.page-404 { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.notfound { text-align: center; display: grid; gap: 12px; justify-items: center; }
.notfound h1 { font-size: 26px; }
