:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1b1e1b;
  --muted: #717771;
  --line: #e6e2d8;
  --brand: #1f7a4d;
  --brand-ink: #13633c;
  --disc: #e0492c;
  --save: #b9810a;
  --save-bg: #fdf3da;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .05), 0 6px 18px rgba(20, 30, 20, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + var(--safe-b));
}
h2 { font-size: 18px; margin: 0; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(244, 241, 234, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font-size: 16px;
}
.area-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font-size: 14px; font-weight: 600; max-width: 60vw;
}
.area-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.area-btn svg:first-child { color: var(--brand); }
.brand {
  font-size: 17px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--brand-ink); user-select: none;
  background: none; border: none; padding: 8px 0;
}
.info-body p { margin: 0 0 14px; line-height: 1.55; }
.info-body h3 { font-size: 14px; font-weight: 700; color: var(--brand-ink); margin: 18px 0 6px; }

/* Active filter chips */
.active-chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 14px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.active-chips::-webkit-scrollbar { display: none; }
.active-chips:not(:empty) { padding: 12px 14px 2px; }
.mini-chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--brand); color: #fff; border: none;
}
.mini-chip .x { opacity: .8; font-weight: 700; }

/* Views */
.view { padding: 12px 14px 20px; max-width: 720px; margin: 0 auto; }
.feed-meta { color: var(--muted); font-size: 13px; margin: 4px 2px 12px; }
.feed { display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; line-height: 1.6; }

/* Offer card */
.card {
  display: flex; gap: 12px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
}
.card-emoji {
  flex: 0 0 52px; width: 52px; height: 52px; border-radius: 13px;
  display: grid; place-items: center; font-size: 26px;
  background: var(--surface-2); align-self: flex-start;
}
.card-main { flex: 1; min-width: 0; }
.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.chain-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.chain-name { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.card-name { font-weight: 600; font-size: 14.5px; line-height: 1.3; }
.src-icon {
  margin-left: auto; display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); padding: 2px; border-radius: 6px; flex: none;
  transition: color .12s, background .12s;
}
.src-icon:hover { color: var(--brand); background: var(--surface-2); }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.price-row { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; }
.price-now { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.price-now .cents { font-size: 15px; }
.price-old { color: var(--muted); text-decoration: line-through; font-size: 13px; }
.disc-badge {
  margin-left: auto; align-self: center;
  background: var(--disc); color: #fff; font-weight: 800; font-size: 13px;
  padding: 3px 8px; border-radius: 8px;
}
.card-right { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.save-btn {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: var(--save-bg); border: 1.5px solid #f0dcab; color: var(--save);
  font-weight: 800; font-size: 18px; transition: transform .12s ease;
}
.save-btn:active { transform: scale(.9); }
.save-btn.saved { background: var(--brand); border-color: var(--brand); color: #fff; }
.save-btn small { font-size: 9px; font-weight: 700; }

/* Savings view */
.savings-hero {
  text-align: center; padding: 28px 16px 24px; margin-bottom: 16px;
  background: linear-gradient(160deg, var(--brand), var(--brand-ink));
  color: #fff; border-radius: 22px; box-shadow: var(--shadow);
}
.savings-label { font-size: 14px; opacity: .85; }
.savings-total { font-size: 46px; font-weight: 800; letter-spacing: -.03em; margin: 4px 0; }
.savings-sub { font-size: 13px; opacity: .85; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab.active { color: var(--brand); }
.badge {
  position: absolute; top: 4px; left: 56%;
  background: var(--disc); color: #fff; font-size: 10px; font-weight: 800; font-style: normal;
  min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  display: grid; place-items: center;
}

/* Drawer + Sheet */
.drawer, .sheet { position: fixed; inset: 0; z-index: 40; }
.drawer-scrim, .sheet-scrim { position: absolute; inset: 0; z-index: 1; background: rgba(20, 25, 20, .4); }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; left: 0; z-index: 2; width: min(86vw, 360px);
  background: var(--bg); display: flex; flex-direction: column;
  animation: slideIn .22s ease;
}
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding-bottom: var(--safe-b); max-height: 86vh; display: flex; flex-direction: column;
  animation: slideUp .24s ease;
}
@keyframes slideIn { from { transform: translateX(-100%); } }
@keyframes slideUp { from { transform: translateY(100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-body, .sheet-body { padding: 16px; overflow-y: auto; flex: 1; }
.drawer-foot { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line); }

.field { display: block; margin-bottom: 20px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
input[type=search] {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px; color: var(--ink);
}
input[type=range] { width: 100%; accent-color: var(--brand); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.btn-primary { flex: 1; padding: 13px; border-radius: 12px; border: none; background: var(--brand); color: #fff; font-weight: 700; font-size: 15px; }
.btn-ghost { padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; }

/* Area sheet */
.gps-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px; border-radius: 12px; border: none; background: var(--brand); color: #fff; font-weight: 700; font-size: 15px;
}
.gps-status { font-size: 13px; color: var(--muted); text-align: center; min-height: 18px; margin-top: 8px; }
.sheet-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.sheet-divider::before, .sheet-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.area-list { display: flex; flex-direction: column; gap: 8px; }
.area-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.area-item.on { border-color: var(--brand); background: #eef6f1; }
.area-item .a-emoji { font-size: 22px; }
.area-item .a-name { font-weight: 700; font-size: 15px; }
.area-item .a-sub { font-size: 12px; color: var(--muted); }
.area-item .a-meta { margin-left: auto; font-size: 12px; color: var(--brand); font-weight: 700; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-b)); z-index: 60;
  background: #1b1e1b; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Työpöytä: suodatinpaneeli pysyvästi vasemmalla ----------
   Leveällä näytöllä drawer ei ole modaali vaan kiinteä sivupalkki.
   Suodatus on jo live (jokainen muutos → render), joten tulokset
   päivittyvät heti vieressä — paneelia ei tarvitse sulkea. */
@media (min-width: 900px) {
  body { padding-left: 320px; }

  /* Drawer-container kutistetaan vasemmaksi kaistaksi (ei peitä sisältöä). */
  #filterDrawer {
    display: block !important;          /* ohita .hidden */
    inset: 0 auto 0 0;                  /* top right bottom left → vain vasen */
    width: 320px;
    z-index: 30;                        /* areaSheet (40) peittää yhä tarvittaessa */
  }
  #filterDrawer .drawer-scrim { display: none; }
  #filterDrawer .drawer-panel {
    position: static;
    width: 320px; height: 100%;
    animation: none;
    background: var(--surface);
    border-right: 1px solid var(--line);
  }
  /* "Valmis"/sulje turhia kun paneeli on aina auki. */
  #filterDrawer #applyFilters,
  #filterDrawer #filterClose { display: none; }
  #filterDrawer #clearFilters { flex: 1; }
  #filterBtn { display: none; }

  /* Kiinteät elementit huomioivat sivupalkin leveyden. */
  .tabbar { left: 320px; }
  .toast { left: calc(50% + 160px); }
}
