/* Design decisions:
   colour      sage backgrounds; dark green #45684A for actions (6.30:1 against white);
               one warm colour, used for price drops only
   type        Rubik; product name 24, price 22, text 16, secondary information 14
   spacing     8 between related lines, 16 between components, 24 between groups; right aligned
   touch       every control has a hit area of at least 44 x 44 */

@font-face { font-family: "Rubik"; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url("fonts/rubik-hebrew.woff2") format("woff2");
  unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F; }
@font-face { font-family: "Rubik"; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url("fonts/rubik-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Rubik"; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url("fonts/rubik-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }

:root {
  color-scheme: light;
  --page: #EEF2EB;            /* sage */
  --sage: #DFE7DB;            /* deeper sage: chips, wells */
  --line: #C9D5C5;
  --surface: #FFFFFF;
  --ink: #1D2A20;
  --ink-2: #4F5E53;
  --action: #45684A;
  --action-down: #38553C;
  --warm: #B0502A;            /* price drops only */
  --s1: 8px; --s2: 16px; --s3: 24px;
  --name: 24px; --price: 22px; --text: 16px; --small: 14px;
  --tabbar: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-text-size-adjust: 100%; }
html.locked { overflow: hidden; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 400 var(--text)/1.5 "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  text-align: right;
  padding-bottom: calc(var(--tabbar) + var(--safe-b));
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--name); font-weight: 700; line-height: 1.25; }
h2 { font-size: var(--name); font-weight: 600; line-height: 1.3; text-wrap: balance; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
        stroke-linecap: round; stroke-linejoin: round; }
.wrap { max-width: 1400px; margin: 0 auto; padding-inline: var(--s2); }
.meta, .summary, .footnote { font-size: var(--small); color: var(--ink-2); }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------------------------------------------------------------- controls */
.btn {
  min-height: 44px; padding: 0 var(--s2); border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s1);
  transition: transform .15s ease-out, background-color .15s ease-out;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--action); color: #fff; }
.btn.primary:hover { background: var(--action-down); }
.btn.secondary { background: var(--surface); color: var(--action); border-color: var(--line); }
.btn.secondary:hover { background: var(--page); }
.btn .icon { width: 20px; height: 20px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--ink);
  display: inline-grid; place-items: center; cursor: pointer; transition: background-color .15s ease-out;
}
.icon-btn:hover { background: var(--sage); }
.count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--action); color: #fff;
  font-size: var(--small); font-weight: 600; line-height: 22px; text-align: center; font-variant-numeric: tabular-nums;
}
input[type=search], input[type=password], select {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit;   /* 16px: iOS does not zoom on focus */
}
input[type=search] { -webkit-appearance: none; appearance: none; }
.field { display: flex; flex-direction: column; gap: var(--s1); }
.field label, .field .label { font-weight: 500; }

.chips { display: flex; gap: var(--s1); overflow-x: auto; scrollbar-width: none; padding-block: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap-chips { flex-wrap: wrap; overflow: visible; }
.chips button {
  position: relative; flex: none; min-height: 40px; padding: 0 var(--s2); border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
  transition: background-color .15s ease-out, color .15s ease-out;
}
.chips button::after { content: ""; position: absolute; inset: -3px 0; }     /* 44px hit area */
.chips button[aria-pressed=true] { background: var(--action); border-color: var(--action); color: #fff; font-weight: 500; }

/* ---------------------------------------------------------------- page frame */
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
            padding-top: calc(var(--s1) + env(safe-area-inset-top, 0px)); }
.filters { position: sticky; top: 0; z-index: 5; background: var(--page); border-bottom: 1px solid var(--line);
           padding-top: calc(var(--s1) + env(safe-area-inset-top, 0px)); padding-bottom: var(--s1); }
.titlebar + .filters { padding-top: var(--s1); }
.filters .wrap { display: flex; flex-direction: column; gap: var(--s1); }
.searchbar { display: flex; gap: var(--s1); }
.searchbar input { flex: 1; min-width: 0; }

.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10; display: flex;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  position: relative; flex: 1; min-height: 44px; border: 0; background: transparent; color: var(--ink-2); font: inherit;
  font-size: var(--small); cursor: pointer; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; transition: color .15s ease-out;
}
.tabs button[aria-current=page] { color: var(--action); font-weight: 600; }
.tabs button[aria-current=page] .icon { stroke-width: 2.4; }
.tabs .count { position: absolute; top: 5px; inset-inline-start: calc(50% + 14px); min-width: 20px; height: 20px; line-height: 20px; }

main { padding-top: var(--s2); padding-bottom: var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.notice { background: var(--sage); border-radius: 10px; padding: var(--s1) var(--s2); }
.footnote { text-wrap: pretty; }

/* ---------------------------------------------------------------- product cards */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s1); }
.card {
  position: relative; display: flex; flex-direction: column; overflow: hidden; background: var(--surface);
  border-radius: 12px; box-shadow: 0 0 0 1px rgba(29, 42, 32, .08), 0 1px 2px rgba(29, 42, 32, .06);
  transition: box-shadow .15s ease-out;
}
.card:hover { box-shadow: 0 0 0 1px rgba(29, 42, 32, .14), 0 4px 12px rgba(29, 42, 32, .10); }
.thumb { position: relative; aspect-ratio: 1 / 1; background: #fff; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: var(--s1); }
.noimg { position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--small); color: var(--ink-2); }
.badges { position: absolute; top: var(--s1); inset-inline-start: var(--s1); display: flex; gap: 4px; }
.badge { border-radius: 999px; padding: 2px 10px; font-size: var(--small); font-weight: 600; line-height: 1.4; }
.badge.rank { background: var(--ink); color: #fff; direction: ltr; font-variant-numeric: tabular-nums; }
.badge.new { background: var(--action); color: #fff; }
.card .open { position: absolute; inset: 0; z-index: 1; border: 0; padding: 0; background: transparent;
              border-radius: 12px; cursor: pointer; }
.card .open:focus-visible { outline-offset: -3px; }
.heart {
  position: absolute; z-index: 2; top: 0; inset-inline-end: 0; width: 44px; height: 44px; border: 0; padding: 0;
  background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--ink);
}
.heart::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: rgba(255, 255, 255, .92);
                 box-shadow: 0 0 0 1px rgba(29, 42, 32, .10), 0 1px 3px rgba(29, 42, 32, .12); }
.heart .icon { position: relative; width: 19px; height: 19px; margin-top: 1px;     /* optical centre of a heart */
               transition: transform .15s ease-out, fill .15s ease-out, color .15s ease-out; }
.heart:active .icon { transform: scale(.86); }
.heart[aria-pressed=true] { color: var(--action); }
.heart[aria-pressed=true] .icon { fill: currentColor; }
.card .body { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s1); flex: 1; }
.card .title { font-size: var(--text); font-weight: 500; line-height: 1.35; text-align: right; overflow-wrap: anywhere;
               display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price { font-size: var(--price); font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.price.none { font-size: var(--small); font-weight: 400; color: var(--ink-2); line-height: 1.5; }
.change { font-size: var(--small); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.change.down { color: var(--warm); font-weight: 600; }
.stats { display: flex; flex-wrap: wrap; gap: 0 var(--s1); font-size: var(--small); color: var(--ink-2);
         font-variant-numeric: tabular-nums; }
.stats b { color: var(--ink); font-weight: 600; }
.bought { align-self: flex-start; font-size: var(--small); background: var(--sage); border-radius: 6px; padding: 2px var(--s1); }
.card .foot { margin-top: auto; font-size: var(--small); color: var(--ink-2); }

.empty { text-align: center; padding: var(--s3) var(--s2); display: flex; flex-direction: column; align-items: center; gap: var(--s1); }
.empty h2 { font-size: var(--price); }
.empty p { color: var(--ink-2); max-width: 44ch; text-wrap: pretty; }
.empty .btn { margin-top: var(--s1); }
#sentinel { height: 1px; }

/* ---------------------------------------------------------------- table (wide screens) */
.tablewrap { overflow-x: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 0 0 1px rgba(29, 42, 32, .08); }
table { border-collapse: collapse; width: 100%; font-size: var(--small); }
th, td { padding: var(--s1) 12px; border-bottom: 1px solid var(--sage); text-align: right; vertical-align: middle; }
th { color: var(--ink-2); font-weight: 600; white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.pic img { width: 48px; height: 48px; object-fit: contain; display: block; }
td.name { min-width: 280px; max-width: 460px; }
td.fav { width: 44px; padding: 0; position: relative; height: 56px; }
td.fav .heart::before { box-shadow: none; background: transparent; }
td.fav .heart { top: 50%; margin-top: -22px; }
.link { border: 0; padding: 0; background: none; color: var(--action); font: inherit; font-weight: 500; cursor: pointer;
        text-align: right; text-decoration: underline; text-underline-offset: 3px; }
.sheet-body table th, .sheet-body table td { padding-inline: var(--s1); }

/* ---------------------------------------------------------------- sheets */
dialog.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%;
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px));
  border-radius: 16px 16px 0 0; background: var(--page); color: var(--ink); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s ease-out; }
dialog.sheet::backdrop { background: rgba(29, 42, 32, .45); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
              padding: var(--s1) var(--s1) var(--s1) var(--s1); padding-inline-start: var(--s2); }
.sheet-head h2 { font-size: var(--price); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
              padding: var(--s1) var(--s2) var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.sheet-body > * { flex: none; }      /* content scrolls; it must not shrink */
.sheet-actions { display: flex; flex-direction: column; gap: var(--s1); border-top: 1px solid var(--line);
                 padding: var(--s2) var(--s2) calc(var(--s2) + var(--safe-b)); }
.wide-only { display: none; }

.photo { position: relative; background: #fff; border-radius: 12px; height: min(46dvh, 360px);
         box-shadow: 0 0 0 1px rgba(29, 42, 32, .08); }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: var(--s2); }
.product-main { display: flex; flex-direction: column; gap: var(--s1); }
.product-main h2 { text-align: right; overflow-wrap: anywhere; text-wrap: pretty; }
.product-main .badges { position: static; flex-wrap: wrap; }
.group { display: flex; flex-direction: column; gap: var(--s1); }
.group h3 { font-size: var(--text); font-weight: 600; }
dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s2); font-size: var(--small); }
dt { color: var(--ink-2); white-space: nowrap; }
dd { margin: 0; overflow-wrap: anywhere; }
.runs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s1); font-size: var(--small); }
.runs li { background: var(--surface); border-radius: 10px; padding: var(--s1) 12px; }
.runs .detail { color: var(--ink-2); overflow-wrap: anywhere; }

.toast {
  position: fixed; z-index: 2147483647; inset-inline: var(--s2); bottom: calc(var(--tabbar) + var(--safe-b) + var(--s2));
  margin-inline: auto; width: fit-content; max-width: calc(100% - 2 * var(--s2));
  background: var(--ink); color: #fff; border-radius: 10px; padding: 10px var(--s2); text-align: center;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .15s ease-out, transform .15s ease-out;
}
.toast.show { opacity: 1; transform: none; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s2); margin-bottom: calc(-1 * (var(--tabbar) + var(--safe-b))); }
.login-card { width: min(100%, 360px); display: flex; flex-direction: column; gap: var(--s2); }
.login-card img { border-radius: 14px; }
.error { color: var(--ink); background: var(--sage); border-radius: 10px; padding: var(--s1) 12px; border-inline-start: 4px solid var(--ink); }

/* ---------------------------------------------------------------- wider screens */
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--s2); }
  .card .body { padding: 12px; }
  .card .title { -webkit-line-clamp: 3; }
}
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .titlebar { padding-top: var(--s2); }
  .titlebar h1 { margin-inline-end: auto; }
  .tabs { position: static; height: auto; padding: 4px; gap: 4px; border: 0; border-radius: 12px; background: var(--sage); }
  .tabs button { flex: none; flex-direction: row; gap: var(--s1); padding: 0 var(--s2); border-radius: 9px; font-size: var(--text); }
  .tabs button[aria-current=page] { background: var(--surface); }
  .tabs .count { position: static; min-width: 22px; height: 22px; line-height: 22px; }
  .filters .wrap { flex-direction: row; align-items: center; gap: var(--s2); }
  .searchbar { flex: 1; max-width: 560px; }
  dialog.sheet { margin: auto; max-width: 720px; max-height: 88dvh; border-radius: 16px; }
  .sheet-actions { flex-direction: row; }
  .sheet-actions .btn { flex: 1; }
  .wide-only { display: flex; }
  .toast { bottom: var(--s3); }
  .login { margin-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
