/* Cesta: tokens de cor (claro e escuro) e componentes. Pensado para o celular, no corredor do mercado. */
:root {
  --bg: #f1f5f2;
  --surface: #ffffff;
  --fg: #14231f;
  --muted: #5a6c66;
  --line: #d6e0db;
  --accent: #0f6b5f;
  --accent-fg: #ffffff;
  --recur: #7a4e00;
  --recur-bg: #fbeecf;
  --danger: #a1342c;
  --display: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1714;
    --surface: #16231f;
    --fg: #e7f0ec;
    --muted: #92a69f;
    --line: #263832;
    --accent: #48c4b0;
    --accent-fg: #06211c;
    --recur: #f0c36a;
    --recur-bg: #3a2e12;
    --danger: #f08e84;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
  padding-block: max(20px, env(safe-area-inset-top, 0px)) max(40px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main, #tela-app { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
h1, h2 { font-family: var(--display); margin: 0; text-wrap: balance; }
h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.01em; }
h2 { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
code { font-size: 0.92em; }
p { margin: 0; }
[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.resumo { margin-top: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.link { background: transparent; border: 0; color: var(--muted); padding: 10px 6px; min-height: 44px; text-decoration: underline; }
.nota { color: var(--muted); font-size: 14px; text-wrap: pretty; }
.erro { color: var(--danger); font-size: 15px; }
.offline { background: var(--recur-bg); color: var(--recur); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

/* Login */
.login { margin-top: 8vh; padding: 20px; }
.login form { display: flex; flex-direction: column; gap: 8px; }
.login label { font-weight: 600; font-size: 14px; margin-top: 4px; }
input[type="email"], input[type="password"], input[type="text"] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 46px; width: 100%;
}
.login .btn-primary { margin-top: 10px; }

/* Adicionar */
.add-row { display: flex; gap: 8px; }
.add-row input { min-width: 0; flex: 1 1 auto; }
#qtd { flex: 0 0 76px; width: 76px; text-align: center; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { text-align: center; padding: 10px 8px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); min-height: 42px; display: flex; align-items: center; justify-content: center; }
.seg input:checked + label { background: var(--surface); color: var(--fg); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.seg input:checked + label.rec { background: var(--recur-bg); color: var(--recur); box-shadow: none; }
.seg input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 1px; }

.btn-primary { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; min-height: 48px; font-weight: 600; padding: 0 18px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sec { background: transparent; border: 1px solid var(--fg); color: var(--fg); border-radius: 10px; min-height: 46px; font-weight: 600; padding: 0 16px; }
.btn-sec:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sec.calmo { border-color: var(--line); color: var(--muted); }

/* Abas */
.abas { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.abas button { background: transparent; border: 0; border-bottom: 3px solid transparent; padding: 12px 8px; min-height: 48px; font-weight: 600; color: var(--muted); }
.abas button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.painel { display: flex; flex-direction: column; gap: 18px; }

/* Listas */
.faixa { display: flex; flex-direction: column; gap: 8px; }
.lista { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 14px; min-height: 52px; }
.item + .item { border-top: 1px solid var(--line); }
.item label, .item .rotulo { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.item label { cursor: pointer; }
.item input[type="checkbox"], .check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 24px; height: 24px; flex: 0 0 24px;
  border: 2px solid var(--muted); border-radius: 7px; margin: 0; display: grid; place-items: center; background: transparent; cursor: pointer;
}
.item input[type="checkbox"]:checked, .check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.item input[type="checkbox"]:checked::after, .check input[type="checkbox"]:checked::after {
  content: ""; width: 6px; height: 11px; border: solid var(--accent-fg); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px);
}
.nome { min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.qtd { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 14px; }
.item.feito .nome { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.tag { border-radius: 999px; padding: 6px 10px; min-height: 34px; font-size: 13px; font-weight: 600; background: transparent; color: var(--muted); border: 1px dashed var(--line); white-space: nowrap; }
.tag[aria-pressed="true"] { background: var(--recur-bg); color: var(--recur); border: 1px solid transparent; }
.del { background: transparent; border: 0; min-width: 44px; height: 44px; border-radius: 10px; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 6px; }
.del:hover { color: var(--danger); }
.del.confirmar { color: var(--danger); font-size: 14px; font-weight: 700; }
.vazio { padding: 22px 16px; color: var(--muted); text-align: center; text-wrap: balance; }

/* Nova compra */
.nova p { color: var(--muted); font-size: 15px; text-wrap: pretty; }
.check { display: flex; align-items: center; gap: 12px; }
.check label { cursor: pointer; }
.confirma { display: flex; gap: 8px; flex-wrap: wrap; }
.confirma .btn-primary { flex: 1 1 180px; }
.confirma .btn-sec { flex: 1 1 110px; }
#nc-box { display: flex; flex-direction: column; gap: 12px; }

.aviso { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: 12px 14px; border-radius: 10px; font-size: 15px; }

@media (prefers-reduced-motion: no-preference) {
  .item, .abas button { transition: background-color .15s, color .15s; }
}
