:root {
  --green: #0f5a3c;
  --green-dark: #0a3d29;
  --green-soft: #e8f5ee;
  --amber-bg: #fff6e5;
  --amber: #b45309;
  --red-bg: #fde8e8;
  --red: #b91c1c;
  --ok: #15803d;
  --text: #1a1a1a;
  --muted: #5c6670;
  --line: #d8e0da;
  --card: #ffffff;
  --radius: 14px;
  --touch: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #f3f6f4; color: var(--text); }
body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.top {
  position: sticky; top: 0; z-index: 10;
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  padding: 12px 14px 10px;
  padding-top: calc(12px + env(safe-area-inset-top));
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.logo { border-radius: 10px; background: #fff; }
.top h1 { margin: 0; font-size: 1.25rem; line-height: 1.2; }
.subtitle { margin: 2px 0 0; font-size: .85rem; opacity: .9; }

.search-wrap { display: block; }
#search {
  width: 100%; min-height: var(--touch);
  border: none; border-radius: 12px;
  padding: 12px 14px; font-size: 1.05rem;
  background: #fff; color: var(--text);
}
#search::placeholder { color: #8a949c; }

.chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 0 4px; margin: 0 -2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(255,255,255,.45);
  background: transparent;
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
}
.chip[aria-pressed="true"] {
  background: #fff;
  color: var(--green-dark);
  border-color: #fff;
}

.meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; font-size: .8rem; opacity: .9;
}
.offline-badge {
  background: #fbbf24; color: #1a1a1a;
  padding: 2px 8px; border-radius: 999px; font-weight: 700;
}

main { padding: 10px 12px 28px; max-width: 720px; margin: 0 auto; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 64px;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.row:active { transform: scale(.99); background: var(--green-soft); }
.row-name { font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.row-sub { color: var(--muted); font-size: .88rem; }
.row-prices {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  gap: 2px; white-space: nowrap;
}
.price-pub { font-weight: 700; font-size: 1.1rem; }
.price-cost { color: var(--muted); font-size: .85rem; }
.margin {
  display: inline-block;
  font-weight: 800;
  font-size: .9rem;
  padding: 2px 8px;
  border-radius: 8px;
  background: #e8f8ee;
  color: var(--ok);
}
.margin.low { background: var(--amber-bg); color: var(--amber); }
.margin.neg { background: var(--red-bg); color: var(--red); }
.margin.na { background: #eee; color: var(--muted); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.detail {
  border: none; border-radius: 18px;
  padding: 0; width: min(96vw, 420px);
  box-shadow: 0 16px 48px rgba(0,0,0,.28);
}
.detail::backdrop { background: rgba(0,0,0,.45); }
.detail-inner { padding: 16px 16px 18px; }
.detail-inner header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  margin-bottom: 12px;
}
.detail-inner h2 { margin: 0; font-size: 1.2rem; line-height: 1.3; }
.close {
  border: none; background: #eef2ef; width: 40px; height: 40px;
  border-radius: 12px; font-size: 1.1rem; cursor: pointer;
}
dl { margin: 0 0 14px; }
dl > div {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
dt { color: var(--muted); font-size: .9rem; }
dd { margin: 0; font-weight: 700; text-align: right; }
.btn-primary {
  width: 100%; min-height: var(--touch);
  border: none; border-radius: 12px;
  background: var(--green); color: #fff;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}

.fmt-badge {
  display: inline-block;
  font-weight: 700;
  font-size: .82rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef2ef;
  color: var(--muted);
  vertical-align: middle;
}
.fmt-badge.fmt-sacco {
  background: #e0f0ff;
  color: #1e40af;
}
.fmt-badge.fmt-sfuso {
  background: #fff3d6;
  color: #92400e;
}
