:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #98a0b0;
  --accent: #6ea8fe;
  --accent-ink: #0b1220;
  --danger: #ff7b72;
  --warn: #f2b84b;
  --ok: #56d364;
  --radius: 12px;
  --tabs-h: 58px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }
a { color: var(--accent); }

/* ---------- estrutura ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}

.capture { display: flex; gap: 8px; max-width: 720px; margin: 0 auto; }
.capture input { flex: 1; min-width: 0; }
.capture .btn { width: 48px; font-size: 1.3rem; padding: 0; }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-right)) calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  height: var(--tabs-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
}
.tab.active { color: var(--accent); }

.badge {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: 20px;
  padding: 0 6px;
  font-size: 0.75rem;
  line-height: 20px;
  text-align: center;
}

/* ---------- campos e botões ---------- */

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { resize: vertical; }
select { width: auto; max-width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .check:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
::placeholder { color: var(--muted); }

.btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.wide { width: 100%; min-height: 46px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.row > input { flex: 1; min-width: 140px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); flex: 1; min-width: 140px; }
.field select { width: 100%; }

/* ---------- listas ---------- */

.section { margin-top: 24px; }
details.section > summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 8px 0; }
details.section[open] > summary { margin-bottom: 8px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.task-main { display: flex; gap: 12px; align-items: flex-start; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-notes { color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 0.8rem; }
.task-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.task.is-done .task-title { color: var(--muted); text-decoration: line-through; }

.check {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.check:hover { border-color: var(--ok); background: rgba(86, 211, 100, 0.15); }

.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--muted); }
.due { color: var(--muted); }
.due.overdue { color: var(--danger); font-weight: 600; }
.count { color: var(--muted); font-weight: 400; }
.tag-hint { color: var(--muted); font-size: 0.8rem; }
.masked { color: var(--muted); letter-spacing: 2px; font-weight: 400; }

.editor { border-top: 1px solid var(--border); padding-top: 10px; }
.project-row { flex-direction: row; align-items: center; justify-content: space-between; }

.empty { color: var(--muted); padding: 16px 0; margin: 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* ---------- Hoje ---------- */

.today-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.today-head h1 { margin: 0; }
.counter { font-size: 1.1rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--warn); }

.notice {
  display: block;
  margin-top: 24px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  font-weight: 600;
}
.key-warning { display: flex; justify-content: space-between; gap: 12px; color: var(--text); text-decoration: none; }

/* ---------- keys ---------- */

.secret {
  display: block;
  font: 0.95rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  user-select: all;
}

.audit { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; color: var(--muted); }
.audit li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.audit-when { flex: none; font-variant-numeric: tabular-nums; }

/* ---------- login e primeiro acesso ---------- */

.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 0; text-align: center; }
.qr { align-self: center; border-radius: 10px; background: #fff; }

/* ---------- aviso flutuante ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}
.toast.error { border-color: var(--danger); color: var(--danger); border-radius: var(--radius); }

@media (prefers-reduced-motion: no-preference) {
  .btn, .check, .tab { transition: border-color 0.12s, background-color 0.12s, color 0.12s; }
}
