:root {
  --verde: #16a34a;
  --verde-claro: #dcfce7;
  --cinza: #6b7280;
  --bg: #f8fafc;
  --card: #ffffff;
  --borda: #e5e7eb;
  --perigo: #dc2626;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: #111827;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  position: sticky;
  top: 0;
  background: #fff;
  color: #111827;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
header .logo { height: 48px; display: block; flex-shrink: 0; }
.contador { font-size: .85rem; color: var(--cinza); white-space: nowrap; margin-left: auto; }

#form-add {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  position: sticky;
  top: 60px;
  background: var(--bg);
  z-index: 9;
}
#campo-item {
  flex: 1;
  padding: 14px 16px;
  font-size: 1rem;
  border: 1px solid var(--borda);
  border-radius: 12px;
  background: var(--card);
}
#campo-item:focus { outline: 2px solid var(--verde); border-color: var(--verde); }
#form-add button {
  width: 52px;
  border: none;
  border-radius: 12px;
  background: var(--verde);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
#form-add button:active { transform: scale(.95); }

main { padding: 0 16px 24px; }

.grupo { margin-top: 18px; }
.grupo h2 {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--cinza);
  margin: 0 0 8px 4px;
}

ul { list-style: none; margin: 0; padding: 0;
  background: var(--card);
  border: 1px solid var(--borda);
  border-radius: 14px;
  overflow: hidden;
}
.lista-unica { margin-top: 16px; }

li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--borda);
  border-left: 6px solid transparent; /* cor da categoria via inline style */
}
li:last-child { border-bottom: none; }

li input[type=checkbox] {
  width: 24px; height: 24px;
  accent-color: var(--verde);
  flex-shrink: 0;
}
li .info { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
li .nome { font-size: 1.05rem; }
li .cat {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
  opacity: .85;
}
li .qtd {
  font-size: .8rem;
  color: var(--verde);
  background: var(--verde-claro);
  padding: 2px 8px;
  border-radius: 999px;
}
li.comprado .nome { text-decoration: line-through; color: var(--cinza); }
li .rm {
  background: none; border: none; color: #cbd5e1;
  font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 6px 8px;
  flex-shrink: 0;
}
li .rm:active { color: var(--perigo); }

.vazio { text-align: center; color: var(--cinza); margin-top: 60px; }

footer {
  display: flex;
  justify-content: space-between;
  padding: 16px;
}
.link {
  background: none; border: none; color: var(--cinza);
  font-size: .9rem; cursor: pointer; text-decoration: underline;
}
.link.perigo { color: var(--perigo); }

/* toast com ação (desfazer) */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #1f2937;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: .95rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast button {
  background: none; border: none; color: #4ade80;
  font-weight: 600; font-size: .95rem; cursor: pointer; padding: 4px;
}

/* botão no header */
.hbtn {
  background: var(--verde-claro); border: none; color: var(--verde);
  font-size: 1.2rem; width: 40px; height: 40px; border-radius: 10px;
  cursor: pointer; flex-shrink: 0;
}
.hbtn:active { transform: scale(.94); }

/* overlay + bottom sheet */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end;
}
.overlay[hidden] { display: none; }
.sheet {
  background: #fff; width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 80vh; overflow-y: auto;
  animation: subir .18s ease-out;
}
@keyframes subir { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { margin: 0 0 14px; font-size: 1.05rem; }
.sheet h3 small { color: var(--cinza); font-weight: 400; font-size: .72rem; }
.fechar {
  margin-top: 14px; width: 100%; padding: 12px;
  background: var(--bg); border: 1px solid var(--borda); border-radius: 12px;
  font-size: .95rem; cursor: pointer; color: var(--cinza);
}

/* lista de escolha de categoria (picker) */
.pick-lista { display: flex; flex-direction: column; gap: 8px; }
.pick-lista button {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--borda); border-radius: 12px;
  background: #fff; font-size: 1rem; cursor: pointer; text-align: left;
  border-left-width: 6px;
}
.pick-lista button .dot { display: none; }

/* gerenciar categorias (arrastável) */
.cat-lista { display: flex; flex-direction: column; gap: 8px; }
.cat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--borda); border-radius: 12px;
  background: #fff; border-left-width: 6px; touch-action: none;
}
.cat-row.arrastando { opacity: .85; box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.cat-row .alca { cursor: grab; font-size: 1.2rem; color: var(--cinza); user-select: none; }
.cat-row .ccor {
  width: 30px; height: 30px; flex-shrink: 0;
  border: none; background: none; padding: 0; border-radius: 6px;
}
.cat-row .cinfo { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-row .cnome { cursor: text; }
.cat-row .cdesc { font-size: .72rem; color: var(--cinza); cursor: text; line-height: 1.25; }
.cat-row .cdesc.vazia { font-style: italic; opacity: .65; }
.cat-row .cdel { background: none; border: none; color: var(--perigo); cursor: pointer; font-size: 1rem; align-self: center; }
.cat-row .cdel[disabled] { color: var(--borda); cursor: default; }

.cat-form { display: flex; gap: 8px; margin-top: 16px; align-items: center; flex-wrap: wrap; }
.cat-desc-input {
  flex-basis: 100%; padding: 10px 12px;
  border: 1px solid var(--borda); border-radius: 10px; font-size: .95rem;
}
.cat-form input[type=color] { width: 44px; height: 44px; border: none; background: none; padding: 0; }
.cat-form input[type=text] {
  flex: 1; padding: 12px; border: 1px solid var(--borda); border-radius: 10px; font-size: 1rem;
}
.cat-form button {
  padding: 12px 16px; border: none; border-radius: 10px;
  background: var(--verde); color: #fff; font-weight: 600; cursor: pointer;
}

/* tela de login (reusa .overlay/.sheet; z-index acima dos demais overlays) */
#login-modal { z-index: 40; }
#login-form input {
  width: 100%; padding: 14px 12px; margin-bottom: 10px;
  border: 1px solid var(--borda); border-radius: 10px; font-size: 1rem;
}
#login-form input:focus { outline: 2px solid var(--verde); border-color: var(--verde); }
#login-form button {
  width: 100%; padding: 14px; border: none; border-radius: 10px;
  background: var(--verde); color: #fff; font-weight: 600; font-size: 1rem; cursor: pointer;
}
.login-erro { color: var(--perigo); font-size: .85rem; margin: 0 0 10px; }
.login-erro[hidden] { display: none; }

/* login: estado "entrando" — o scrypt é lento de propósito e o servidor é
   pequeno, então a espera precisa ser VISÍVEL, senão a pessoa clica de novo */
#login-form button[disabled] { opacity: .65; cursor: progress; }
#login-modal.ocupado .sheet { cursor: progress; }
#login-modal.ocupado input { opacity: .7; }
/* visível só para leitor de tela */
.so-leitor {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
#login-form button[disabled]::after {
  content: ''; display: inline-block; width: 12px; height: 12px; margin-left: 8px;
  vertical-align: -2px; border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff; border-radius: 50%; animation: girando .7s linear infinite;
}
@keyframes girando { to { transform: rotate(360deg); } }
