/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --brand:      #2563eb;
  --brand-dark: #1e3a8a;
  --brand-lite: #eff6ff;
  --green:      #16a34a;
  --green-bg:   #f0fdf4;
  --orange:     #ea580c;
  --orange-bg:  #fff7ed;
  --red:        #dc2626;
  --red-bg:     #fef2f2;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --muted:      #94a3b8;
  --text:       #0f172a;
  --text2:      #475569;
  --radius-sm:  8px;
  --radius:     14px;
  --radius-lg:  20px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 4px 16px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg:  0 10px 40px rgba(0,0,0,.1), 0 2px 8px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0a0f1e;
    --surface:  #131929;
    --border:   #1e293b;
    --text:     #f1f5f9;
    --text2:    #94a3b8;
    --brand-lite: #1e293b;
    --green-bg:  #052e16;
    --orange-bg: #1c0f00;
    --red-bg:    #1c0000;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow:    0 4px 16px rgba(0,0,0,.3);
  }
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue',
    'Noto Sans Hebrew', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100dvh; width: 100%; overflow-x: hidden; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  background: linear-gradient(145deg, #1d4ed8 0%, #1e3a8a 60%, #172554 100%);
  color: #fff;
  padding: 28px 20px 36px;
  position: relative;
  overflow: hidden;
}

/* decorative circles */
.header::before,
.header::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  pointer-events: none;
}
.header::before { width: 220px; height: 220px; top: -80px; left: -60px; }
.header::after  { width: 160px; height: 160px; bottom: -60px; right: 10%; }

.header-inner {
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.header-icon {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.2);
}

.header-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.header-sub {
  font-size: .88rem;
  color: rgba(255,255,255,.7);
  margin-top: 4px;
  font-weight: 400;
}

/* Search pulled down from header */
.search-wrapper {
  max-width: 600px;
  margin: -22px auto 0;
  padding: 0 12px;
  position: relative;
  z-index: 5;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 12px 88px;
}

/* ── Category filter bar ─────────────────────────────────────────────────── */
.category-bar {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 6px;
  padding: 10px 16px 4px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  scrollbar-width: none;
  box-sizing: border-box;
}
.category-bar::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.cat-chip:hover { border-color: var(--brand); color: var(--brand); }
.cat-chip-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.cat-count {
  font-size: .68rem;
  font-weight: 400;
  opacity: .75;
  margin-right: 3px;
}

/* ── Search box ───────────────────────────────────────────────────────────── */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 12px;
  box-shadow: var(--shadow-lg);
  transition: border-color .2s, box-shadow .2s;
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(37,99,235,.12);
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1.05rem;
  background: transparent;
  color: var(--text);
  direction: rtl;
  min-width: 0;
  padding: 4px 0;
  font-family: inherit;
}
.search-input::placeholder { color: var(--muted); }

.search-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 12px;
  width: 42px; height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.search-btn:hover  { background: var(--brand-dark); }
.search-btn:active { transform: scale(.95); }

/* ── Status bar ───────────────────────────────────────────────────────────── */
.status-bar {
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: .02em;
}

/* ── Result card ─────────────────────────────────────────────────────────── */
.result-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow .18s, transform .15s;
}
.result-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
}

.merchant-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.category-badge {
  background: var(--brand-lite);
  color: var(--brand);
  font-size: .68rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: .02em;
  margin-top: 2px;
}

/* ── Benefit row ─────────────────────────────────────────────────────────── */
.benefit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.card-label {
  font-size: .78rem;
  font-weight: 700;
  min-width: 80px;
  letter-spacing: .01em;
}
.card-label--sheli    { color: #1d4ed8; }
.card-label--isracard { color: #7c3aed; }
.card-label--max      { color: #e65c00; }

.benefit-info {
  flex: 1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

/* ── Status pill ─────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: .01em;
}
.pill-discount { background: var(--green-bg);  color: var(--green);  font-weight: 800; font-size: .85rem; }
.pill-sheli    { background: #dbeafe;          color: #1d4ed8;       font-weight: 800; font-size: .82rem; }
.pill-accepted { background: #f1f5f9;          color: var(--muted);  }
.pill-orange   { background: var(--orange-bg); color: var(--orange); }
.pill-red      { background: var(--red-bg);    color: var(--red);    }
.pill-max      { background: #fff3e0;          color: #e65c00;       font-weight: 800; font-size: .85rem; }

/* ── Best-deal comparison banner ─────────────────────────────────────────── */
.best-deal {
  font-size: .78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
}
.best-deal-isracard { background: #f0fdf4; color: #15803d; }
.best-deal-sheli    { background: #eff6ff; color: #1d4ed8; }
.best-deal-tie      { background: #fafafa; color: var(--muted); }

/* ── Channel tags ────────────────────────────────────────────────────────── */
.channel-tag {
  font-size: .72rem;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
}

/* ── Empty / no-data ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text2);
}
.empty-icon {
  font-size: 3.2rem;
  margin-bottom: 16px;
  filter: grayscale(.3);
}
.empty-state p { font-size: .95rem; margin-bottom: 8px; }
.empty-hint    { font-size: .83rem; color: var(--muted); }
.empty-state code {
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 5px;
  font-family: monospace;
  font-size: .82em;
  color: var(--brand);
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--muted);
  z-index: 10;
  backdrop-filter: blur(8px);
}
.refresh-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  transition: all .15s;
}
.refresh-btn:hover { color: var(--brand); border-color: var(--brand); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: block;
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; justify-content: center; padding: 40px; }

/* ── Fade-in for cards ───────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result-card { animation: fadeUp .18s ease both; }

/* ── Mobile optimisations ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Prevent iOS/Android zoom on input focus */
  .search-input { font-size: 16px; }

  /* Tighter header on small screens */
  .header { padding: 20px 16px 30px; }

  /* Bigger touch targets for chips */
  .cat-chip { min-height: 36px; padding: 6px 14px; font-size: .8rem; }

  /* Stack card label above pills in benefit rows */
  .benefit-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 14px;
  }
  .card-label { min-width: unset; }

  /* Allow best-deal text to wrap */
  .best-deal { font-size: .74rem; line-height: 1.5; }

  /* Slightly tighter card padding */
  .card-header { padding: 12px 14px 8px; }

  /* Larger search button tap area */
  .search-btn { width: 46px; height: 46px; }

  /* More breathing room in main */
  .main { padding: 12px 10px 80px; }
}
