:root {
  --green: #34c759; --green-d: #248a3d; --blue: #007aff; --red: #ff3b30;
  --bg: #f2f2f7;            /* iOS grouped background */
  --cell: #ffffff;          /* cell background */
  --ink: #000000;
  --label2: rgba(60,60,67,.6);    /* secondary label */
  --label3: rgba(60,60,67,.3);    /* tertiary label */
  --sep: rgba(60,60,67,.29);      /* separator */
  --fill: rgba(118,118,128,.12);  /* tertiary fill (steppers, search) */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  letter-spacing: -.01em;
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ---------- Nav bar (large title) ---------- */
.nav {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-t) + 8px) 16px 8px;
  background: rgba(242,242,247,.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid transparent;
  display: flex; align-items: flex-end; justify-content: space-between;
}
.nav h1 { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.nav-add {
  border: 0; background: none; color: var(--green); cursor: pointer;
  padding: 2px; display: grid; place-items: center; border-radius: 50%;
}
.nav-add:active { opacity: .4; }
.nav-add[hidden] { display: none; }

.view { flex: 1; overflow-y: auto; padding: 8px 16px calc(96px + var(--safe-b)); }

/* ---------- Section header ---------- */
.sec-h {
  font-size: 13px; font-weight: 400; color: var(--label2);
  margin: 22px 16px 7px; display: flex; justify-content: space-between;
  text-transform: uppercase; letter-spacing: -.01em;
}
.sec-h .ct { color: var(--label3); }
.view > .sec-h:first-child { margin-top: 6px; }

/* ---------- Inset grouped list ---------- */
.group {
  background: var(--cell); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 0 0 .5px rgba(0,0,0,.04);
}
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; min-height: 48px; position: relative; background: var(--cell);
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 52px; right: 0;
  height: .5px; background: var(--sep);
}
.row:active { background: #d1d1d6; }

/* leading check (iOS circular) */
.chk {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 1.8px solid #c7c7cc; background: #fff;
  display: grid; place-items: center; cursor: pointer; transition: .12s;
}
.chk svg { width: 16px; height: 16px; opacity: 0; }
.row.on .chk { background: var(--green); border-color: var(--green); }
.row.on .chk svg { opacity: 1; stroke: #fff; }

.info { flex: 1; min-width: 0; }
.nome { font-size: 17px; font-weight: 400; line-height: 1.25; letter-spacing: -.02em; }
.meta { font-size: 14px; color: var(--label2); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }

/* stepper (iOS) */
.qty { display: flex; align-items: center; background: var(--fill);
  border-radius: 9px; flex: none; height: 32px; overflow: hidden; }
.qty button {
  width: 38px; height: 32px; border: 0; background: none; cursor: pointer;
  font-size: 21px; color: var(--ink); display: grid; place-items: center; line-height: 1;
}
.qty button:active { background: rgba(0,0,0,.06); }
.qty .n { min-width: 26px; text-align: center; font-weight: 600; font-size: 16px;
  font-variant-numeric: tabular-nums; }
.qty .sep { width: .5px; height: 18px; background: var(--sep); flex: none; }

/* ---------- Search (iOS) ---------- */
.search {
  width: 100%; padding: 9px 14px 9px 36px; border: 0; background: var(--fill);
  border-radius: 10px; font-size: 17px; margin: 4px 0 6px; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 11px center;
}
.search::placeholder { color: #8e8e93; }
.search:focus { outline: none; }

/* ---------- Comparar ---------- */
.cmp-tot { display: flex; gap: 12px; margin: 4px 0 10px; }
.cmp-card {
  flex: 1; background: var(--cell); border-radius: var(--radius); padding: 16px 12px;
  text-align: center; box-shadow: 0 0 0 .5px rgba(0,0,0,.04);
}
.cmp-card.win { background: var(--green); }
.cmp-card .lbl { font-size: 13px; color: var(--label2); font-weight: 500; }
.cmp-card.win .lbl { color: rgba(255,255,255,.85); }
.cmp-card .val { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; }
.cmp-card.win .val { color: #fff; }
.cmp-card .win-tag { font-size: 11px; font-weight: 600; margin-top: 2px;
  color: rgba(255,255,255,.9); text-transform: uppercase; letter-spacing: .02em; }
.cmp-note { font-size: 13px; color: var(--label2); margin: 0 4px 12px; letter-spacing: -.01em; }
.cmp-row { display: flex; align-items: center; gap: 8px; padding: 11px 16px;
  background: var(--cell); position: relative; }
.cmp-row + .cmp-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0;
  height: .5px; background: var(--sep); }
.cmp-row .nm { flex: 1; font-size: 16px; letter-spacing: -.02em; }
.cmp-row .nm small { color: var(--label3); }
.cmp-row .pc { width: 72px; text-align: right; font-size: 15px;
  font-variant-numeric: tabular-nums; color: var(--label2); }
.cmp-row .pc.best { color: var(--green-d); font-weight: 600; }
.cmp-row .pc.miss { color: var(--label3); }

/* ---------- Mercado ---------- */
.mkt-chk {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  border: 1.8px solid #c7c7cc; background: #fff; display: grid; place-items: center; transition: .12s;
}
.mkt-chk svg { width: 17px; height: 17px; opacity: 0; }
.row.got { }
.row.got .mkt-chk { background: var(--green); border-color: var(--green); }
.row.got .mkt-chk svg { opacity: 1; stroke: #fff; }
.row.got .nome { color: var(--label3); text-decoration: line-through; }
.row.got .meta { color: var(--label3); }

/* ---------- Histórico ---------- */
.hist { background: var(--cell); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 12px; box-shadow: 0 0 0 .5px rgba(0,0,0,.04); }
.hist .hh { display: flex; justify-content: space-between; align-items: baseline; }
.hist .hh .dt { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
.hist .hh .tot { font-size: 17px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; }
.hist .hi { font-size: 14px; color: var(--label2); margin-top: 5px; line-height: 1.35; }

/* ---------- Cards / Config ---------- */
.card { background: var(--cell); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: 0 0 0 .5px rgba(0,0,0,.04); }
.card h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; letter-spacing: -.02em; }
.card p { margin: 0 0 14px; font-size: 15px; color: var(--label2); line-height: 1.4; }

.btn { width: 100%; background: var(--green); color: #fff; border: 0; border-radius: 12px;
  padding: 13px 16px; font-size: 17px; font-weight: 600; cursor: pointer;
  letter-spacing: -.02em; }
.btn:active { opacity: .85; }
.btn:disabled { background: var(--fill); color: var(--label3); }
.btn-danger { background: #fff; color: var(--red); box-shadow: inset 0 0 0 1px var(--sep); }
.btn-ghost { background: none; border: 0; color: var(--blue); padding: 13px 16px;
  font-size: 17px; cursor: pointer; }
.btn-row { display: flex; gap: 12px; margin-top: 6px; }

/* ---------- Empty ---------- */
.empty { text-align: center; color: var(--label2); padding: 64px 32px; }
.empty .ico { color: var(--label3); margin-bottom: 12px; }
.empty .ico svg { width: 52px; height: 52px; }
.empty p { font-size: 16px; line-height: 1.4; margin: 0; letter-spacing: -.01em; }

/* ---------- Tab bar (translucent) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: rgba(249,249,249,.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep);
  display: flex; padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; border: 0; background: none; padding: 7px 0 2px; cursor: pointer;
  color: #999; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab svg { width: 26px; height: 26px; }
.tab span { font-size: 10px; font-weight: 500; letter-spacing: 0; }
.tab.active { color: var(--green); }

/* ---------- Dialog ---------- */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg form { padding: 22px; }
.dlg h2 { margin: 0 0 16px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.dlg label { display: block; font-size: 13px; color: var(--label2); margin-bottom: 14px;
  font-weight: 500; }
.dlg input, .dlg select { width: 100%; padding: 11px 12px; border: 0; background: var(--fill);
  border-radius: 10px; font-size: 17px; margin-top: 5px; color: var(--ink);
  -webkit-appearance: none; }
.dlg input:focus, .dlg select:focus { outline: 2px solid var(--green); }
.row2 { display: flex; gap: 12px; }
.row2 label { flex: 1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 4px; align-items: center; }

/* ---------- Toast / banner ---------- */
.toast { position: fixed; bottom: calc(86px + var(--safe-b)); left: 50%;
  transform: translateX(-50%) translateY(20px); background: rgba(28,28,30,.95); color: #fff;
  padding: 11px 20px; border-radius: 999px; font-size: 15px; font-weight: 500; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 20; letter-spacing: -.01em;
  backdrop-filter: blur(10px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.config-banner { background: #fff3cd; border-radius: var(--radius); color: #664d03;
  padding: 14px 16px; font-size: 14px; line-height: 1.45; margin-bottom: 14px; }
