:root {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-2: #efebe1;
  --text: #1d2420;
  --muted: #6b726d;
  --line: #e3ddd0;
  --brand: #1f6f50;
  --brand-ink: #ffffff;
  --brand-soft: #e1efe7;
  --soon: #b45309;
  --soon-soft: #fdf0dc;
  --urgent: #c2341d;
  --urgent-soft: #fde6e1;
  --gray-soft: #ecebe7;
  --shadow: 0 1px 2px rgba(40, 35, 20, .06), 0 4px 14px rgba(40, 35, 20, .06);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a17;
    --surface: #1f2622;
    --surface-2: #28302b;
    --text: #eef1ee;
    --muted: #9aa49e;
    --line: #333c36;
    --brand: #4fb389;
    --brand-ink: #0d1a14;
    --brand-soft: #1f3a2e;
    --soon: #f0a54a;
    --soon-soft: #3a2a14;
    --urgent: #ff7a63;
    --urgent-soft: #45201a;
    --gray-soft: #2b302d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Rubik', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ltr { direction: ltr; unicode-bidi: isolate; }
[hidden] { display: none !important; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 110px);
}

/* כותרת */
.top {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px; margin-bottom: 8px;
}
.top h1 { font-size: 24px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.01em; }
.top h2 { font-size: 19px; font-weight: 600; margin: 0; flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0;
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }

/* סיכום */
.summary {
  background: var(--brand); color: var(--brand-ink);
  border-radius: var(--radius); padding: 18px 20px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.summary .label { font-size: 14px; opacity: .85; }
.summary .total { font-size: 32px; font-weight: 700; line-height: 1.1; }
.summary .side { text-align: left; font-size: 14px; opacity: .92; }
.summary .warn { display: inline-block; margin-top: 4px; background: rgba(255,255,255,.18); border-radius: 99px; padding: 2px 10px; font-weight: 500; }

/* חיפוש וסינון */
.search {
  width: 100%; height: 46px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 14px; font-size: 16px; outline: none;
}
.search:focus { border-color: var(--brand); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-inline-start: 4px; }

/* כרטיסי שוברים */
.list { display: grid; gap: 10px; margin-top: 12px; }
.card {
  display: flex; gap: 14px; align-items: center;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; border: 0; text-align: start; width: 100%;
  position: relative; overflow: hidden;
}
.card::before { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: var(--brand); }
.card.soon::before { background: var(--soon); }
.card.urgent::before { background: var(--urgent); }
.card.expired::before, .card.done::before { background: var(--line); }
.card.done, .card.expired { opacity: .72; }
.thumb {
  width: 56px; height: 56px; border-radius: 12px; flex: none; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
}
.thumb svg { width: 26px; height: 26px; }
.card .main { flex: 1; min-width: 0; }
.card .store { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; }
.card .value { font-weight: 700; font-size: 20px; flex: none; text-align: left; }
.card .value small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); text-align: left; }
.due { font-weight: 500; }
.due.soon { color: var(--soon); }
.due.urgent { color: var(--urgent); }
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 99px;
  background: var(--surface-2); font-size: 12.5px; font-weight: 500; color: var(--text);
}
.badge.used { background: var(--brand-soft); color: var(--brand); }
.badge.refunded { background: var(--gray-soft); color: var(--muted); }
.badge.expired { background: var(--urgent-soft); color: var(--urgent); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 44px; margin-bottom: 6px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* כפתור הוספה צף */
.fab-wrap {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 5;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  display: flex; justify-content: center; pointer-events: none;
}
.fab {
  pointer-events: auto;
  height: 58px; padding: 0 28px; border-radius: 99px; border: 0;
  background: var(--brand); color: var(--brand-ink);
  font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 6px 20px rgba(31, 111, 80, .35);
  width: 100%; max-width: 528px; justify-content: center;
}
.fab svg { width: 24px; height: 24px; }

/* כפתורים */
.btn {
  height: 52px; border-radius: 14px; border: 0; padding: 0 18px;
  font-size: 17px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); color: var(--text); width: 100%;
}
a.btn { text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: transparent; color: var(--urgent); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn:disabled { opacity: .55; }
.btn svg { width: 20px; height: 20px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 10px; }

/* טפסים */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 4px; font-size: 17px; }
.panel p { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > span { font-size: 14px; font-weight: 500; color: var(--muted); }
.input {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); padding: 10px 12px; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--brand); background: var(--surface); }
textarea.input { min-height: 80px; resize: vertical; }
input[type="date"].input { appearance: none; -webkit-appearance: none; text-align: right; display: block; }
.amount-wrap { position: relative; }
.amount-wrap .input { padding-inline-start: 34px; }
.amount-wrap::before { content: '₪'; position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; height: 40px; border-radius: 9px; font-size: 15.5px; font-weight: 500; color: var(--muted);
}
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }

.photo-box { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); margin-bottom: 14px; }
.photo-box img { display: block; width: 100%; max-height: 340px; object-fit: contain; background: #fff; }
.scan-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 10px;
  background: rgba(20, 26, 22, .55); color: #fff; font-weight: 500; text-align: center; padding: 16px;
}
.scan-line { position: absolute; inset-inline: 0; height: 3px; background: #7be0b3; box-shadow: 0 0 18px #7be0b3; animation: scan 1.6s ease-in-out infinite alternate; }
@keyframes scan { from { top: 8%; } to { top: 92%; } }
.notice { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; }
.notice.ok { background: var(--brand-soft); color: var(--brand); }
.notice.warn { background: var(--soon-soft); color: var(--soon); }
.notice a { color: inherit; font-weight: 600; }

/* מסך שובר */
.hero { text-align: center; padding: 6px 0 14px; }
.hero .store { font-size: 26px; font-weight: 700; margin: 0; }
.hero .value { font-size: 40px; font-weight: 700; color: var(--brand); line-height: 1.15; margin-top: 2px; }
.hero .badges { display: flex; justify-content: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.code-box {
  background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.code-box .code { flex: 1; font-size: 22px; font-weight: 600; letter-spacing: .04em; word-break: break-all; font-variant-numeric: tabular-nums; }
.code-box .label { font-size: 13px; color: var(--muted); }
.copy-btn { height: 40px; padding: 0 14px; border-radius: 12px; border: 0; background: var(--brand-soft); color: var(--brand); font-weight: 600; flex: none; }
.rows { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px; margin-bottom: 14px; }
.row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); flex: none; }
.row .v { text-align: left; font-weight: 500; white-space: pre-wrap; word-break: break-word; }
.photo-thumb { display: block; width: 100%; border: 0; padding: 0; border-radius: var(--radius); overflow: hidden; background: #fff; margin-bottom: 14px; box-shadow: var(--shadow); }
.photo-thumb img { display: block; width: 100%; max-height: 260px; object-fit: cover; object-position: top; }
.photo-thumb .hint { display: block; padding: 8px; font-size: 14px; color: #555; background: #fff; }

/* מסך מלא לצילום (להצגה בקופה) */
.viewer { position: fixed; inset: 0; z-index: 30; background: #fff; display: grid; place-items: center; padding: calc(var(--safe-top) + 10px) 10px calc(var(--safe-bottom) + 10px); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .close { position: absolute; top: calc(var(--safe-top) + 12px); inset-inline-start: 12px; background: rgba(0,0,0,.65); color: #fff; }

/* חלון קופץ */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(10, 14, 12, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(var(--safe-bottom) + 16px); animation: up .2s ease-out;
}
.sheet h3 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 0 0 16px; color: var(--muted); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* כניסה */
.login { min-height: 100dvh; display: grid; align-content: center; justify-items: center; padding: 24px 16px; text-align: center; }
.login .logo { width: 96px; height: 96px; border-radius: 24px; box-shadow: var(--shadow); margin-bottom: 14px; }
.login h1 { margin: 0 0 4px; font-size: 28px; }
.login p { margin: 0 0 22px; color: var(--muted); max-width: 320px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 10px; }
.login .error { color: var(--urgent); min-height: 22px; font-size: 15px; }

/* הודעה קופצת */
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--safe-bottom) + 92px); z-index: 40;
  max-width: 528px; margin: 0 auto; background: var(--text); color: var(--bg);
  border-radius: 14px; padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { transform: none; opacity: 1; pointer-events: auto; }
.toast span { flex: 1; }
.toast button { background: none; border: 0; color: var(--bg); font-weight: 700; text-decoration: underline; padding: 4px; }

.boot { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(127,127,127,.25); border-top-color: currentColor; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { margin: 0; padding-inline-start: 20px; color: var(--text); }
.steps li { margin-bottom: 6px; }
