/* ---------- cores (claro / escuro automático) ---------- */
:root {
  color-scheme: light dark;
  --bg: #f8f9f5;
  --surface: #ffffff;
  --surface-2: #f0f3ee;
  --hover: #f3f6f1;
  --border: #e5e9e2;
  --border-strong: #d3ddd3;
  --text: #202b24;
  --text-2: #5d6d61;
  --text-3: #626f66;
  --logo: #263c2f;
  --brand: #70a17a;
  --accent: #294b37;
  --accent-hover: #396b4c;
  --on-accent: #ffffff;
  --accent-soft: #e6eee4;
  --on-accent-soft: #33523e;
  --check: #527f5e;
  --check-border: #b3c1b4;
  --ring: #dbebdc;
  --focus: #6f9c7b;
  --danger: #b0473d;
  --danger-soft: #fcf0ee;
  --warn: #8a6020;
  --info-soft: #eef5ea;
  --on-info-soft: #3d5e45;
  --count: #eef1ec;
  --on-count: #5d6f62;
  --count-selected: #436550;
  --on-count-selected: #e7f1e7;
  --toast: #243d2d;
  --on-toast: #ffffff;
  --toast-action: #b4e0b6;
  --backdrop: rgba(15, 29, 21, .42);
  --shadow: 0 6px 24px rgba(36, 57, 38, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111612;
    --surface: #19201b;
    --surface-2: #232c25;
    --hover: #212a23;
    --border: #29322b;
    --border-strong: #3a473d;
    --text: #e5ebe6;
    --text-2: #aab7ad;
    --text-3: #8d9b90;
    --logo: #e5ebe6;
    --brand: #82b68d;
    --accent: #3d6e4e;
    --accent-hover: #4a805d;
    --on-accent: #ffffff;
    --accent-soft: #263529;
    --on-accent-soft: #b9d5bf;
    --check: #5f9a6d;
    --check-border: #5d6c61;
    --ring: #284633;
    --focus: #82b68d;
    --danger: #f08b80;
    --danger-soft: #3a2421;
    --warn: #e2bf78;
    --info-soft: #1f3125;
    --on-info-soft: #b9d5bf;
    --count: #29332c;
    --on-count: #aab7ad;
    --count-selected: #2c5039;
    --on-count-selected: #e0eee3;
    --toast: #e5ebe6;
    --on-toast: #142019;
    --toast-action: #2c6b41;
    --backdrop: rgba(0, 0, 0, .6);
    --shadow: none;
  }
}

/* ---------- base ---------- */
:root {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  --composer-h: calc(79px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-width: 300px; background: var(--bg); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button svg { flex-shrink: 0; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.logo { font-size: 24px; font-weight: 820; letter-spacing: -1.5px; line-height: 1; color: var(--logo); }
.logo span { color: var(--brand); }
.logo.large { font-size: 40px; letter-spacing: -2.6px; }

/* ---------- botões ---------- */
.btn { min-height: 52px; border: 0; border-radius: 14px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-size: 15px; font-weight: 700; background: none; }
.btn.full { width: 100%; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--accent-soft); color: var(--on-accent-soft); }
.btn.subtle { color: var(--text-2); min-height: 44px; }
.btn.destructive { background: var(--danger); color: var(--surface); }
.icon-button { height: 44px; width: 44px; display: grid; place-items: center; background: transparent; border: 1px solid var(--border); border-radius: 13px; color: var(--text-2); padding: 0; }
.icon-button:hover { background: var(--hover); }
.icon-button.muted-icon { border: 0; color: var(--text-3); margin-right: -8px; }
.top-gap { margin-top: 12px; }

/* ---------- cabeçalho fixo (logo + grupos) ---------- */
.shell { min-height: 100dvh; padding-bottom: calc(var(--composer-h) + 16px); }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.top-inner, .content, .tabs-inner { width: min(100% - 2 * var(--gutter), 680px); margin: 0 auto; }
.top-inner { height: 56px; display: flex; align-items: center; justify-content: space-between; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.connection { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.connection.offline { color: var(--danger); }
.connection.syncing { color: var(--warn); }

.group-scroll { overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.group-scroll::-webkit-scrollbar { display: none; }
.tabs-inner { padding: 2px 0 12px; }
.groups { display: flex; align-items: center; gap: 8px; width: max-content; padding-right: var(--gutter); }
.group-tab, .group-add { min-height: 44px; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 0 14px; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 650; color: var(--text-2); white-space: nowrap; }
.group-tab:hover, .group-add:hover { border-color: var(--border-strong); }
.group-tab.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.group-count { min-width: 24px; height: 24px; border-radius: 8px; padding: 0 6px; background: var(--count); color: var(--on-count); font-size: 12px; display: grid; place-items: center; }
.selected .group-count { background: var(--count-selected); color: var(--on-count-selected); }
.group-add { background: transparent; border-style: dashed; border-color: var(--border-strong); gap: 6px; color: var(--text-2); }

/* ---------- lista ---------- */
.content { padding-top: 14px; }
.list-section { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 10px 18px; }
.section-head h2 { font-size: 19px; letter-spacing: -.5px; font-weight: 750; overflow-wrap: anywhere; }
.section-head p { font-size: 13px; color: var(--text-3); margin-top: 3px; }
.item-list { list-style: none; margin: 0; padding: 0 6px 6px; }
.item { display: flex; align-items: center; gap: 4px; min-height: 56px; border-top: 1px solid var(--border); padding: 4px 4px 4px 2px; scroll-margin-top: calc(130px + env(safe-area-inset-top)); scroll-margin-bottom: calc(var(--composer-h) + 12px); }
.item-name { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; background: none; border: 0; padding: 6px; border-radius: 8px; text-align: left; font-size: 16px; font-weight: 540; line-height: 1.35; overflow-wrap: anywhere; cursor: text; }
.item-name:hover { background: var(--hover); }
.item-edit { flex: 1; min-width: 0; height: 44px; font-size: 16px; font-weight: 540; color: var(--text); background: var(--surface); border: 1px solid var(--focus); border-radius: 10px; padding: 0 10px; outline: 0; box-shadow: 0 0 0 3px var(--ring); }
.item.done .item-name { color: var(--text-3); text-decoration: line-through; text-decoration-thickness: 1.2px; }

/* Caixa de marcar: área de toque de 44px, quadrado visível de 26px */
.check-btn { width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; padding: 0; flex-shrink: 0; color: #ffffff; }
.check-btn::before { content: ''; grid-area: 1 / 1; width: 26px; height: 26px; box-sizing: border-box; border-radius: 9px; border: 1.7px solid var(--check-border); background: var(--surface); }
.check-btn svg { grid-area: 1 / 1; position: relative; }
.check-btn:hover::before { border-color: var(--check); }
.check-btn.checked::before { background: var(--check); border-color: var(--check); }
.item-delete { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; color: var(--text-3); border-radius: 10px; padding: 0; flex-shrink: 0; }
.item-delete:hover { background: var(--danger-soft); color: var(--danger); }

.empty-list { padding: 22px 20px 30px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.empty-symbol { width: 56px; height: 56px; border-radius: 18px; background: var(--info-soft); color: var(--brand); display: grid; place-items: center; margin-bottom: 12px; }
.empty-list h3 { font-size: 17px; letter-spacing: -.3px; }
.empty-list p { margin-top: 5px; color: var(--text-3); font-size: 14px; }

.done-section { border-top: 1px solid var(--border); }
.done-heading { min-height: 52px; padding: 0 12px 0 14px; display: flex; justify-content: space-between; align-items: center; }
.done-toggle, .clear-done { min-height: 44px; background: transparent; border: 0; display: flex; align-items: center; gap: 8px; padding: 0 6px; color: var(--text-2); font-weight: 650; font-size: 14px; border-radius: 10px; }
.done-toggle span { font-size: 12px; background: var(--count); color: var(--on-count); padding: 3px 9px; border-radius: 20px; }
.clear-done { color: var(--danger); }

/* ---------- barra de adicionar (fixa, acima do teclado) ---------- */
.composer { position: fixed; bottom: 0; left: 0; right: 0; z-index: 8; background: var(--bg); border-top: 1px solid var(--border); padding: 12px var(--gutter) max(12px, env(safe-area-inset-bottom)); }
.composer-inner { margin: 0 auto; max-width: 680px; display: flex; align-items: center; gap: 10px; }
.composer-fields { flex: 1; min-width: 0; height: 54px; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; color: var(--text-3); cursor: text; }
.composer-fields:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px var(--ring); }
.composer-fields input { flex: 1; width: 100%; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--text); }
.composer-fields input::placeholder { color: var(--text-3); }
.composer-fields input:focus-visible { outline: 0; }
.add-button { width: 54px; height: 54px; border: 0; border-radius: 16px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex-shrink: 0; padding: 0; }
.add-button:hover { background: var(--accent-hover); }

/* ---------- modais (folha inferior no celular) ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 30; background: var(--backdrop); display: flex; justify-content: center; align-items: flex-end; }
.modal { position: relative; width: min(100%, 500px); max-height: 90dvh; overflow-y: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 26px max(22px, env(safe-area-inset-left)) max(24px, env(safe-area-inset-bottom)); }
.modal h2 { font-size: 22px; letter-spacing: -.6px; line-height: 1.25; padding-right: 48px; overflow-wrap: anywhere; }
.modal p { font-size: 15px; line-height: 1.6; color: var(--text-2); margin: 10px 0 20px; }
.modal-close { position: absolute; right: 14px; top: 14px; width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; padding: 0; }
.modal-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; margin-bottom: 16px; color: var(--brand); background: var(--info-soft); }
.modal-icon.warning { color: var(--danger); background: var(--danger-soft); }
.modal input { width: 100%; height: 54px; border: 1px solid var(--border-strong); border-radius: 13px; background: var(--surface); padding: 0 15px; color: var(--text); font-size: 16px; outline: none; }
.modal input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--ring); }
.option-menu { display: flex; flex-direction: column; margin-top: 16px; }
.option-menu button { width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: flex-start; gap: 14px; padding: 16px 4px; background: none; border: 0; border-top: 1px solid var(--border); color: var(--text); font-size: 16px; text-align: left; }
.option-menu button.danger { color: var(--danger); }

/* ---------- aviso rápido ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--composer-h) + 10px); z-index: 40; width: max-content; min-width: min(100vw - 32px, 300px); max-width: min(100vw - 32px, 460px); min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 4px 6px 4px 16px; border-radius: 14px; background: var(--toast); color: var(--on-toast); font-size: 14px; line-height: 1.35; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.toast button { min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--toast-action); font-weight: 800; }

/* ---------- carregando / erro / login ---------- */
.loading { min-height: 100dvh; display: flex; justify-content: center; align-items: center; gap: 20px; flex-direction: column; }
.spinner { height: 28px; width: 28px; border: 3px solid var(--ring); border-top-color: var(--check); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-shell { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: max(32px, env(safe-area-inset-top)) var(--gutter) max(40px, env(safe-area-inset-bottom)); }
.center-inner { width: min(100%, 400px); }
.fatal-title { font-size: 24px; margin-top: 34px; }
.fatal-text { line-height: 1.6; margin: 12px 0 24px; color: var(--text-2); overflow-wrap: anywhere; }
.login-title { font-size: clamp(26px, 7vw, 32px); letter-spacing: -1.2px; line-height: 1.2; font-weight: 770; margin-top: 30px; }
.login-copy { color: var(--text-2); font-size: 15px; line-height: 1.6; margin: 10px 0 24px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { font-weight: 700; font-size: 14px; color: var(--text-2); }
.stack input { width: 100%; height: 54px; border: 1px solid var(--border-strong); border-radius: 13px; background: var(--surface); padding: 0 15px; color: var(--text); font-size: 16px; outline: none; }
.stack input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--ring); }
#login-code { font-size: 22px; letter-spacing: 6px; text-align: center; }
.row-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { padding: 0 6px; }
.login-sent { display: flex; gap: 10px; align-items: flex-start; background: var(--info-soft); color: var(--on-info-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.login-sent svg { margin-top: 2px; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 11px 14px; font-size: 14px; line-height: 1.5; margin-bottom: 14px; }

/* ---------- telas maiores ---------- */
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 24px; padding: 30px; }
  .content { padding-top: 20px; }
}
/* ---------- telas muito estreitas ---------- */
@media (max-width: 359px) {
  .connection span { display: none; }
  .group-tab, .group-add { padding: 0 11px; gap: 8px; }
}

/* ---------- código de recuperação e convites ---------- */
.code-value { margin: 6px 0 12px; padding: 16px 10px; border: 1px dashed var(--border-strong); border-radius: 14px; background: var(--surface-2); color: var(--text); font: 700 clamp(17px, 5.2vw, 22px)/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 1px; text-align: center; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
.hint { font-size: 14px; line-height: 1.55; color: var(--text-2); margin: 14px 0; }
.modal p.hint { margin: 14px 0; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .5px; overflow-wrap: anywhere; }
.confirm-check { display: flex; align-items: center; gap: 12px; min-height: 48px; margin: 4px 0 12px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 15px; font-weight: 600; cursor: pointer; }
.confirm-check input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--check); }
.modal .spinner { margin: 8px auto 4px; }
.center-inner .stack .btn + .btn { margin-top: 0; }
/* Aviso rápido: com um menu aberto (que ocupa a parte de baixo), aparece no topo; nunca bloqueia toques fora do botão. */
.toast { pointer-events: none; }
.toast button { pointer-events: auto; }
.modal-open .toast { top: calc(env(safe-area-inset-top) + 12px); bottom: auto; }
/* Lista de passos (ex.: "Perdi o código") */
.modal ul.steps { margin: 0 0 8px; padding-left: 20px; color: var(--text-2); font-size: 15px; line-height: 1.55; }
.modal ul.steps li + li { margin-top: 8px; }
.modal .stack { margin-bottom: 4px; }
/* Passos numerados grandes (convite para usar no app) */
.big-steps { margin: 0 0 18px; padding-left: 24px; color: var(--text); font-size: 17px; line-height: 1.5; }
.big-steps li + li { margin-top: 10px; }
.big-steps li::marker { font-weight: 800; color: var(--brand); }
